Ejemplo n.º 1
1
 public bool init()
 {
     m_player = new WMPLib.WindowsMediaPlayer();
     IWMPSettings2 settings = (IWMPSettings2)m_player.settings;
     bool b = settings.requestMediaAccessRights("full");
     if (!b)
         return b;
     m_media = m_player.mediaCollection;
     return true;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加文件,视频文件或PPT
        /// </summary>
        /// <param name="path">文件路径</param>
        private void AddFile(string path)
        {
            try
            {
                string fileName = path.Substring(path.LastIndexOf("\\") + 1);
                fileName = fileName.Substring(0, fileName.LastIndexOf("."));
                //查看lstBox是否已存在要添加的文件,不存在则继续添加
                for (int i = 0; i < playList.Items.Count; i++)
                {
                    if (playList.Items[i].ToString() == fileName)
                    {
                        playList.SelectedIndex = i;
                        return;
                    }
                }

                if (Path.GetExtension(path).ToLower() == ".ppt" || Path.GetExtension(path).ToLower() == ".pptx")
                {
                    mediaPlayer.currentPlaylist.clear();
                    btnHideList.Visible     = false;
                    grpBoxContainer.Visible = false;
                    mediaPlayer.Visible     = false;
                    browserPPT.Visible      = true;
                    browserPPT.Parent       = mediaPlayArea;
                    browserPPT.Dock         = DockStyle.Fill;
                    browserPPT.Navigate(path, false);

                    isBrowPPT = true;
                    //设置PPT的自动翻页时间,10秒
                    Timer turnPptTimer = new Timer();
                    turnPptTimer.Interval = 10000;
                    turnPptTimer.Tick    += new EventHandler(delegate(object sender1, EventArgs e1)
                    {
                        SendKeys.Send("{RIGHT}");
                        if (browserPPT.ReadyState == WebBrowserReadyState.Complete)
                        {
                        }
                    });
                    turnPptTimer.Start();
                }
                else
                {
                    mediacollection = mediaPlayer.mediaCollection;
                    media           = mediacollection.add(path);
                    mediaPlayer.currentPlaylist.appendItem(media);
                    mediacollection.remove(media, false);//可省
                    playList.Items.Add(fileName);
                    playList.SelectedIndex = playList.Items.Count - 1;
                    if (!playListDict.ContainsKey(fileName))
                    {
                        playListDict.Add(fileName, path);
                        SavePlayListToXml();
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }
Ejemplo n.º 3
0
 public WmpLib()
 {
     IWMPSettings2 settings = (IWMPSettings2)player.settings;
     bool b = settings.requestMediaAccessRights("full");
     if (!b)
         throw new ApplicationException("No rights to modify media library");
     collection = player.mediaCollection;
 }
Ejemplo n.º 4
0
        public WmpLib()
        {
            IWMPSettings2 settings = (IWMPSettings2)player.settings;
            bool          b        = settings.requestMediaAccessRights("full");

            if (!b)
            {
                throw new ApplicationException("No rights to modify media library");
            }
            collection = player.mediaCollection;
        }
Ejemplo n.º 5
0
        private void SaveWMPLibraryData(NHibernate.ISession pDataSession)
        {
            // Hip hip hooray for procedural......
            WindowsMediaPlayerClass WMP     = new WindowsMediaPlayerClass();
            IWMPMediaCollection     mc      = WMP.mediaCollection;
            IWMPStringCollection    strings = mc.getAttributeStringCollection("AlbumID", "audio");

            var albumArtistLookup = new System.Collections.Hashtable();

            int WmpCount = strings.count;

            if (WmpCount > 0)
            {
                for (int i = 0; i < WmpCount; i++)
                {
                    string       item     = strings.Item(i);
                    IWMPPlaylist playlist = mc.getByAttribute("AlbumID", item);
                    playlist.setItemInfo("SortAttribute", "OriginalIndex");
                    int playlistCount = playlist.count;
                    if (playlistCount > 0)
                    {
                        for (int ic = 0; ic < playlistCount; ic++)
                        {
                            IWMPMedia mMedia = playlist.get_Item(ic);

                            string guid        = mMedia.getItemInfo("WM/WMCollectionID");
                            string albumTitle  = mMedia.getItemInfo("WM/AlbumTitle");
                            string albumArtist = mMedia.getItemInfo("WM/AlbumArtist");

                            FileInfo file = new FileInfo(mMedia.sourceURL);

                            //Add to array if not found
                            if (!string.IsNullOrEmpty(guid) && !string.IsNullOrEmpty(albumTitle) &&
                                !albumArtistLookup.ContainsKey(file.DirectoryName))
                            {
                                albumArtistLookup[file.DirectoryName] = true;

                                string filePathLarge = System.IO.Path.Combine(file.DirectoryName, string.Format(WMP_LARGE_GUID, guid));
                                string filePathSmall = System.IO.Path.Combine(file.DirectoryName, string.Format(WMP_SMALL_GUID, guid));

                                if (File.Exists(filePathLarge))
                                {
                                    CreateAndSaveLargeArt(albumArtist, albumTitle, filePathLarge, pDataSession);
                                }
                                if (File.Exists(filePathSmall))
                                {
                                    CreateAndSaveSmallArt(albumArtist, albumTitle, filePathSmall, pDataSession);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public WMP()
        {
            _mediaPlayer = new WindowsMediaPlayer();
            _media       = _mediaPlayer.mediaCollection;

            _titleIndex              = _media.getMediaAtom("Title");
            _albumArtistIndex        = _media.getMediaAtom("WM/AlbumArtist");
            _authorIndex             = _media.getMediaAtom("Author");
            _albumIndex              = _media.getMediaAtom("Album");
            _playCountIndex          = _media.getMediaAtom("PlayCount");
            _userLastPlayedTimeIndex = _media.getMediaAtom("UserLastPlayedTime");
        }
Ejemplo n.º 7
0
    /// <summary>
    /// Constructor.
    /// </summary>
    public WMP()
    {
      _mediaPlayer = new WindowsMediaPlayer();
      _media = _mediaPlayer.mediaCollection;

      _titleIndex = _media.getMediaAtom("Title");
      _albumArtistIndex = _media.getMediaAtom("WM/AlbumArtist");
      _authorIndex = _media.getMediaAtom("Author");
      _albumIndex = _media.getMediaAtom("Album");
      _playCountIndex = _media.getMediaAtom("PlayCount");
      _userLastPlayedTimeIndex = _media.getMediaAtom("UserLastPlayedTime");
    }
Ejemplo n.º 8
0
        /// <summary>
        /// Set a value for the MediaCollection variable based on user settings.
        /// </summary>
        private void GetMediaCollection()
        {
            if (chkLegacyMC.CheckState != CheckState.Checked)
            {
                MediaCollection = Player.mediaCollection;
            }
            else
            {
                IWMPLibrary library = LibSvcs.getLibraryByType(WMPLibraryType.wmpltLocal, 0);
                MediaCollection = library.mediaCollection;
            }

            runCurrentReport();
        }
Ejemplo n.º 9
0
        public AlbumCollection GetAlbums()
        {
            throw new NotImplementedException();
            IWMPMediaCollection media     = wmp.mediaCollection;
            IWMPPlaylist        playlist  = media.getAll();
            List <Album>        albumlist = new List <Album>();

            for (int i = 0; i < playlist.count; i++)
            {
                IWMPMedia temp = playlist[i];
                if (temp.getItemInfo("MediaType") == "audio")
                {
                    string albumname = temp.getItemInfo("Album");
                }
            }
            AlbumCollection albums = new AlbumCollection(albumlist);

            return(albums);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Set a value for the MediaCollection variable based on user settings.
        /// </summary>
        private void GetMediaCollection()
        {
            if (chkLegacyMC.CheckState != CheckState.Checked)
            {
                MediaCollection = Player.mediaCollection;
            }
            else
            {
                IWMPLibrary library = LibSvcs.getLibraryByType(WMPLibraryType.wmpltLocal, 0);
                MediaCollection = library.mediaCollection;
            }

            runCurrentReport();
        }
Ejemplo n.º 11
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //Setting values into initialized variables
            myPing             = new Ping();
            buffer1            = new byte[32];
            timeout            = 1000;
            pingOptions        = new PingOptions();
            mp.URL             = "";
            media              = mp.mediaCollection;
            mp.settings.volume = VolumeSlider.Value * 7;
            request1           = WebRequest.Create("http://193.200.42.211:80/pulstranceHD.mp3");
            request2           = WebRequest.Create("http://163.172.169.217:80/asp-s");
            request3           = WebRequest.Create("http://185.40.31.39:7999/1/;.m3u");
            timer              = new Timer();
            timer.Interval     = (3 * 1000);
            timer.Tick        += new EventHandler(timer_tick);
            timer2             = new Timer();
            timer2.Interval    = (3 * 1000);
            timer2.Tick       += new EventHandler(timer2_tick);
            this.MaximizeBox   = false;


            radioButton1.Enabled = false;
            radioButton2.Enabled = false;
            radioButton3.Enabled = false;
            //Checking if there is an established connection to the internet
            try
            {
                reply = myPing.Send(host, timeout, buffer1, pingOptions);
            }
            catch
            {
                errorState = 1;
                timer2.Start();
            }

            //try
            //{
            //response1 = (HttpWebResponse)request1.GetResponse();
            //response2 = (HttpWebResponse)request2.GetResponse();
            //response3 = (HttpWebResponse)request3.GetResponse();

            //}catch
            //{
            //  MessageBox.Show("You are currently disconnected from the internet! Music streaming services will not be available without a connection!", "Notice");
            //errorState = 1;
            //}


            if (errorState != 1)
            {
                timer.Start();
            }

            //Checking if the streams are currently online, if not disable the connection and the assigned button
            //  if (response1 == null || response1.StatusCode != HttpStatusCode.OK)
            //{
            // MessageBox.Show("Note: Trance stream is currently down!","Notice");

            //}


            //Load Saved Favorite Songs
            list = Properties.Settings.Default.Songs;
            if (list != null)
            {
                foreach (String list2 in list)
                {
                    FavBox.Items.Add(list2);
                }
            }
        }
    /// <summary>
    /// Returns a collection of Song objects from the Windows Media Player library.
    /// </summary>
    /// <returns></returns>
    public static IEnumerable<WmpSong> GetSongsFromLibrary()
    {
      WMPLib.WindowsMediaPlayer wmp = new WMPLib.WindowsMediaPlayer();
      IWMPMediaCollection media = wmp.mediaCollection;
      IWMPPlaylist pList = media.getAll();

      for (int i = 0; i < pList.count; i++)
      {
        IWMPMedia item = pList.get_Item(i);

        WmpSong currentSong = new WmpSong();
        if (item.getItemInfo("CanonicalFiletype") == "mp3")
        {
          foreach (LibraryField libField in Enum.GetValues(typeof(LibraryField)))
          {
            string attrName;
            switch (libField)
            {
              case LibraryField.AlbumTitle:
                {
                  attrName = "WM/AlbumTitle";
                  currentSong.AlbumTitle = item.getItemInfo(attrName);
                  break;
                }

              case LibraryField.ArtistName:
                {
                  attrName = "WM/AlbumArtist";
                  currentSong.ArtistName = item.getItemInfo(attrName);
                  break;
                }

              case LibraryField.CollectionId:
                {
                  attrName = "WM/WMCollectionID";
                  currentSong.WmCollectionId = item.getItemInfo(attrName);
                  break;
                }

              case LibraryField.DateAdded:
                {
                  attrName = "AcquisitionTime";
                  string dateAddedStr = item.getItemInfo(attrName);
                  //Convert from UTC time
                  DateTime utcDateAdded = DateTime.SpecifyKind(DateTime.Parse(dateAddedStr), DateTimeKind.Utc);
                  currentSong.DateAdded = utcDateAdded.ToLocalTime();
                  break;
                }

              case LibraryField.Duration:
                {
                  attrName = "Duration";
                  currentSong.Duration = double.Parse(item.getItemInfo(attrName));
                  break;
                }

              //TODO: Add Label support!

              case LibraryField.LastPlayed:
                {
                  attrName = "UserLastPlayedTime";
                  string lastPlayedStr = item.getItemInfo(attrName);
                  if (!string.IsNullOrEmpty(lastPlayedStr))
                  {
                    //Convert from UTC time
                    DateTime utcLastPlayed = DateTime.SpecifyKind(DateTime.Parse(lastPlayedStr), DateTimeKind.Utc);
                    currentSong.LastPlayed = utcLastPlayed.ToLocalTime();
                  }
                  break;
                }

              case LibraryField.ReleaseDate:
                {
                  attrName = "ReleaseDate";
                  string releaseDateStr = item.getItemInfo(attrName);
                  if (!string.IsNullOrEmpty(releaseDateStr))
                    currentSong.ReleaseDate = DateTime.Parse(releaseDateStr).Date;
                  break;
                }

              case LibraryField.SongTitle:
                {
                  attrName = "Title";
                  currentSong.SongTitle = item.getItemInfo(attrName);
                  break;
                }

              case LibraryField.SongTrackingId:
                {
                  attrName = "TrackingID";
                  currentSong.SongTrackingId = item.getItemInfo(attrName);
                  break;
                }

              case LibraryField.SourceUrl:
                {
                  attrName = "SourceURL";
                  currentSong.SourceUrl = item.getItemInfo(attrName);
                  break;
                }

              case LibraryField.TrackNumber:
                {
                  attrName = "WM/TrackNumber";
                  currentSong.TrackNumber = int.Parse(item.getItemInfo(attrName));
                  break;
                }

              default:
                continue;
            }
          }

          yield return currentSong;
        }
      }
    } 
Ejemplo n.º 13
0
        public SongCollection GetSongs()
        {
            IWMPMediaCollection media    = wmp.mediaCollection;
            IWMPPlaylist        playlist = media.getAll();
            List <Song>         songlist = new List <Song>();

            for (int i = 0; i < playlist.count; i++)
            {
                IWMPMedia temp = playlist[i];
                if (temp.getItemInfo("MediaType") == "audio")
                {
                    int  wmprating;
                    int  rating;
                    int  tracknumber;
                    int  playcount;
                    bool IsProtected;
                    if (!int.TryParse(temp.getItemInfo("UserRating"), out wmprating))
                    {
                        throw new Exception();
                    }
                    if (wmprating >= 87)
                    {
                        rating = 10;
                    }
                    else if (wmprating >= 63)
                    {
                        rating = 8;
                    }
                    else if (wmprating >= 38)
                    {
                        rating = 6;
                    }
                    else if (wmprating >= 13)
                    {
                        rating = 4;
                    }
                    else if (wmprating >= 1)
                    {
                        rating = 2;
                    }
                    else
                    {
                        rating = 0;
                    }
                    if (!int.TryParse(temp.getItemInfo("WM/TrackNumber"), out tracknumber))
                    {
                        tracknumber = 0;
                    }
                    if (!int.TryParse(temp.getItemInfo("PlayCount"), out playcount))
                    {
                        throw new Exception();
                    }
                    if (!bool.TryParse(temp.getItemInfo("Is_Protected"), out IsProtected))
                    {
                        throw new Exception();
                    }
                    TimeSpan duration = new TimeSpan(0, 0, 0, 0, (int)(temp.duration * 1000.0));
                    songlist.Add(new Song(temp.name, duration, rating, tracknumber, temp, mediasource));
                }
            }
            SongCollection songs = new SongCollection(songlist);

            return(songs);
        }