Example #1
0
 /// <summary>
 /// Checks if user has set auto play next checkbox
 /// </summary>
 /// <param name="NewState"></param>
 private void Playah_PlayStateChange(int NewState)
 {
     if (!AutoPlayNext && NewState == (int)WMPPlayState.wmppsMediaEnded)
     {
         Playah.close();
     }
 }
Example #2
0
        private void btnSet_Click(object sender, EventArgs e)
        {
            //When we click btnSet it means that we
            //1) want to set our alarm
            //2) Made a mistake and changed options and pressed set again

            //If there was an alarm set, and timenarration is on, we need to turn it off
            if (_narrationTask != null)
            {
                _tokenSource.Cancel();
            }

            //Just to be sure, delete the media player too
            if (_mediaPlayer != null)
            {
                _mediaPlayer.close();
            }

            //If there is a timer running stop it
            if (_alarmObject != null)
            {
                _alarmObject.Exit();
            }

            //Use the factorymethod to create a timerobject and start it
            _alarmObject = CreateAlarmTimer(_alarmTime);
            _alarmObject.Start();
        }
Example #3
0
        private void Player_PlayStateChange(int NewState)
        {
            var state = (WMPLib.WMPPlayState)NewState;

            //state.Dump();

            switch (state)
            {
            case WMPPlayState.wmppsUndefined:
                break;

            case WMPPlayState.wmppsStopped:
                this.progressBar1.Value = (int)(_player.controls.currentPosition);
                _player.close();
                _player.currentPlaylist = _player.playlistCollection.newPlaylist("myplaylist");
                this.PlayBtn.Text       = "播放";
                _timer.Stop();
                break;

            case WMPPlayState.wmppsPaused:
                break;

            case WMPPlayState.wmppsPlaying:
                break;

            case WMPPlayState.wmppsScanForward:
                break;

            case WMPPlayState.wmppsScanReverse:
                break;

            case WMPPlayState.wmppsBuffering:
                break;

            case WMPPlayState.wmppsWaiting:
                break;

            case WMPPlayState.wmppsMediaEnded:
                break;

            case WMPPlayState.wmppsTransitioning:
                break;

            case WMPPlayState.wmppsReady:
                break;

            case WMPPlayState.wmppsReconnecting:
                break;

            case WMPPlayState.wmppsLast:
                break;

            default:
                break;
            }
        }
Example #4
0
 private void gameform_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (needagain == false)
     {
         form1.Visible = true;
         GameData.gameformbackground.Close();
         wmplayer.close();
         meattacksound.Dispose();
     }
 }
Example #5
0
 public void OpenFile(string fileUrl)
 {
     if (_player.playState.ToString() != "wmppsPlaying")
     {
         _player.network.bufferingTime = 2;
         _player.URL = fileUrl;
     }
     else
     {
         _player.close(); OpenFile(fileUrl);
     }
 }
Example #6
0
 private void Wplayer_StatusChange(int newState)
 {
     if (newState != (int)WMPPlayState.wmppsPlaying)
     {
         IWMPPlaylist playList = wplayer.mediaCollection.getAll();
         if (playList.count >= 1)
         {
             IWMPMedia3 media = (IWMPMedia3)playList.get_Item(0);
             wplayer.mediaCollection.remove(media, true);
         }
         wplayer.close();
     }
 }
Example #7
0
        private void timerPlaying_Tick(object sender, EventArgs e)
        {
            sound.close();
            playingTime = playingDate - DateTime.Now;

            if (playingTime > TimeSpan.FromSeconds(1))
            {
                playSound(cmbSounds.SelectedIndex);
            }
            else
            {
                timerPlaying.Stop();
            }
        }
Example #8
0
 /// <summary>
 /// no matter why you close the form,
 /// we should show the parent form,
 /// or it would be a bad news.
 /// </summary>
 private void Game5_FormClosed(object sender, FormClosedEventArgs e)
 {
     wmp.close();
     parent.Show();
     parent.resetSkin();
     Game5.C_FOLDER = null;
 }
Example #9
0
        public List <RPMusicSong> GetAllSongs()
        {
            if (!Settings.Default.EnableMusicLibrary)
            {
                return(new List <RPMusicSong>());
            }

            WindowsMediaPlayer WMPlayer = new WindowsMediaPlayer();
            List <RPMusicSong> output   = new List <RPMusicSong>();

            // Find all songs
            IWMPPlaylist pl = WMPlayer.mediaCollection.getByAttribute("MediaType", "Audio");

            for (int s = 0; s < pl.count; s++)
            {
                IWMPMedia song = pl.get_Item(s);

                RPMusicSong RPsong = CreateRPMusicSongFromIWMPMediaSong(song);
                if (RPsong != null)
                {
                    output.Add(RPsong);
                }
            }

            WMPlayer.close();
            return(output);
        }
Example #10
0
        public List <RPMusicGenre> GetAllGenres()
        {
            if (!Settings.Default.EnableMusicLibrary)
            {
                return(new List <RPMusicGenre>());
            }

            WindowsMediaPlayer  WMPlayer = new WindowsMediaPlayer();
            List <RPMusicGenre> output   = new List <RPMusicGenre>();

            IWMPStringCollection scGenres = WMPlayer.mediaCollection.getAttributeStringCollection("Genre", "Audio");

            for (int i = 0; i < scGenres.count; i++)
            {
                RPMusicGenre genre = new RPMusicGenre(scGenres.Item(i));
                output.Add(genre);
            }

            WMPlayer.close();

            // Sort output A-Z
            CommonEPG.Comparers.RPMusicGenreTitleComparer myComparer = new CommonEPG.Comparers.RPMusicGenreTitleComparer();
            output.Sort(myComparer);

            return(output);
        }
        public static void CacheMediaLibrary()
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback((state)=>
                {
                    List<Album> returnedAlbums = new List<Album>();
                    WindowsMediaPlayer mediaPlayer = null;

                    try
                    {
                        //LogUtility.LogMessage("Started caching");

                        mediaPlayer = new WindowsMediaPlayer();
                        CacheAlbums(mediaPlayer);
                        CacheArtists(mediaPlayer);
                        CacheAlbumArtists(mediaPlayer);

                        //LogUtility.LogMessage("Finished caching");
                    }
                    catch (Exception ex)
                    {
                        LogUtility.LogException(ex);
                        throw;
                    }
                    finally
                    {
                        if (mediaPlayer != null)
                        {
                            mediaPlayer.close();
                        }
                    }
                }));
        }
Example #12
0
        public List <RPMusicArtist> GetAllArtists()
        {
            if (!Settings.Default.EnableMusicLibrary)
            {
                return(new List <RPMusicArtist>());
            }

            WindowsMediaPlayer WMPlayer = new WindowsMediaPlayer();

            List <RPMusicArtist> output     = new List <RPMusicArtist>();
            List <RPMusicArtist> outputList = new List <RPMusicArtist>();
            IWMPStringCollection scArtists  = WMPlayer.mediaCollection.getAttributeStringCollection("Author", "Audio");

            for (int i = 0; i < scArtists.count; i++)
            {
                string strArtistName = scArtists.Item(i);
                if (string.IsNullOrEmpty(strArtistName))
                {
                    continue;                                      // Believe it or not WMP sometimes returns an empty artist name
                }
                RPMusicArtist artist = new RPMusicArtist(strArtistName);
                output.Add(artist);
            }

            WMPlayer.close();

            // Sort output A-Z
            CommonEPG.Comparers.RPMusicArtistNameComparer myComparer = new CommonEPG.Comparers.RPMusicArtistNameComparer();
            output.Sort(myComparer);

            return(output);
        }
Example #13
0
        static void Exit()
        {
            lock (Icon) {
                if (Exiting)
                {
                    return;
                }
                Exiting = true;
            }
            var maxvol = Player.settings.volume;
            var vol    = maxvol;

            if (vol > 1)
            {
                var delay = Mute / vol;
                while (vol > 0)
                {
                    Player.settings.volume--;
                    vol--;
                    Thread.Sleep(delay);
                }
            }
            Player.controls.stop();
            Player.settings.volume = maxvol;
            Player.close();
            Icon.Visible = false;
            Application.Exit();
        }
Example #14
0
 public void ThreadProc()
 {
     Thread.Sleep(_decalage * 1000);
     _player.controls.play();
     Thread.Sleep(_duree * 1000);
     _player.close();
 }
Example #15
0
        public static void RestartGame(WindowsMediaPlayer bgm)
        {
            string result;

            do
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine();
                Console.WriteLine("                                               Play again ?");
                Console.Write("                                             [y]es or [n]o >");
                result = (Console.ReadLine()).ToLower();
                if (result == "y")
                {
                    Console.WriteLine();
                    Console.Write("                                        Press Enter to Play Again >");
                    Console.ReadKey();
                    // Off BGM
                    bgm.close();
                    // Call Main() to restart the Console App
                    Program.Main();
                }
                else if (result == "n")
                {
                    Console.WriteLine();
                    Console.WriteLine("                                           Thanks for Playing :)");
                    Console.ReadKey();
                }
            } while (result != "y" && result != "n");
        }
Example #16
0
 /// <summary>
 /// Closes the media player.
 /// </summary>
 public void Dispose()
 {
     if (_mediaPlayer != null)
     {
         _mediaPlayer.close();
     }
 }
Example #17
0
        void ISoundNotificationPlayer.Play(string file)
        {
            wasTryingToPlay = true;

            if (player.URL != file)
            {
                player.close();
                player.URL          = file;
                ignorePlaybackError = false;
            }
            else
            {
                player.controls.stop();
            }

            player.controls.play();
        }
Example #18
0
 private void wplayer_Change(int newState)
 {
     // stop
     if (newState == 1)
     {
         _wplayer.close();
     }
 }
Example #19
0
        public TimeSpan GetVideoLength(string videoPath)
        {
            var player = new WindowsMediaPlayer();
            var video  = player.newMedia(videoPath);
            var ret    = TimeSpan.FromSeconds(video.duration);

            player.close();
            return(ret);
        }
Example #20
0
        private async void playSound(int soundIndex)
        {
            sound     = new WindowsMediaPlayer();
            sound.URL = soundFiles[soundIndex];
            sound.controls.play();
            await Task.Delay(2000);

            sound.close();
        }
Example #21
0
        public Bitmap ThumbnailForWMPItem(string WMPMatchAttribute, string itemID, bool useFolderArtIfFound, Thumbnail_Sizes size, out string MimeType)
        {
            // Get URL
            MimeType = "";
            string             picFileName;
            WindowsMediaPlayer WMPlayer = new WindowsMediaPlayer();

            IWMPPlaylist pl = WMPlayer.mediaCollection.getByAttribute(WMPMatchAttribute, itemID);

            if (pl.count == 0)
            {
                Functions.WriteLineToLogFile("Warning - no items found in library with ID " + itemID);
                return(null);
            }

            //if (pl.count != 1) Functions.WriteLineToLogFile("Warning - more than one item found in library with ID " + itemID);

            IWMPMedia pic = pl.get_Item(0);

            picFileName = pic.sourceURL;

            WMPlayer.close();

            if (useFolderArtIfFound)
            {
                string itemFolder  = Path.GetDirectoryName(picFileName);
                string folderArtFN = Path.Combine(itemFolder, "folder.jpg");
                if (File.Exists(folderArtFN))
                {
                    picFileName = folderArtFN;
                }
            }


            ShellHelper shellHelper = new ShellHelper();

            MimeType = "image/jpeg";
            string strLog = ""; // ignore

            switch (size)
            {
            case Thumbnail_Sizes.Small:
                return(shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Small, ref strLog));

            case Thumbnail_Sizes.Medium:
                return(shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Medium, ref strLog));

            case Thumbnail_Sizes.Large:
                return(shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Large, ref strLog));

            case Thumbnail_Sizes.ExtraLarge:
                return(shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.ExtraLarge, ref strLog));

            default:
                return(shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Small, ref strLog));
            }
        }
Example #22
0
 private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
 {
     //Утилизация WMP.
     //Есть сомнения в целесообразности этого кода
     wmp.close();
     Marshal.FinalReleaseComObject(wmp);
     wmp = null;
     GC.Collect();
 }
Example #23
0
        public void PlayMusic(Music music)
        {
            player.controls.stop();
            player.close();

            AddToCache(music);

            player.URL = Cache[music.MID];
            player.controls.play();
        }
        public WmpTagReader(string filename)
        {
            var player = new WindowsMediaPlayer();
            var media = player.newMedia(filename);
            player.close();

            title = media.getItemInfo("Title");
            album = media.getItemInfo("Album");
            artist = media.getItemInfo("Author");
            trackNo = media.getItemInfo("OriginalIndex");
        }
Example #25
0
    static string foodSymbol = '■'.ToString();//"@";
    static void Main()
    {
        Console.SetWindowSize(85, 26);
        Console.SetBufferSize(85, 26);
        Console.CursorVisible = false;
        WindowsMediaPlayer menuMusic = new WindowsMediaPlayer();

        menuMusic.URL = "inMenu.wav";
        menuMusic.settings.setMode("loop", true);
        menuMusic.settings.volume = 50;
        menuMusic.controls.play();

        int    result = 0;
        string name   = null;
        string speed  = null;
        string level  = null;

        while (true)
        {
            result = MainMenu();
            if (result == 1)
            {
                direction = 3;
                name      = InputName();
                speed     = SpeedSelect();
                level     = LevelSelect();
                menuMusic.controls.stop();
                PlayGame(name, speed, level);
                menuMusic.controls.play();
                GameOver();
            }
            else if (result == 2)
            {
                HighScores();
            }
            else if (result == 3)
            {
                menuMusic.settings.mute = !menuMusic.settings.mute;
            }
            else if (result == 4)
            {
                Manual();
            }
            else if (result == 5)
            {
                result = AreYouSure();
                if (result == 1)
                {
                    menuMusic.close();
                    return;
                }
            }
        }
    }
 private void Player_PlayChangeState(int newState)
 {
     if ((WMPPlayState)newState == WMPPlayState.wmppsStopped)
     {
         mediaPlayer.close();
         l_speakerStatus.Visible = false;
     }
     if (mediaPlayer.playState == WMPPlayState.wmppsPlaying)
     {
         l_speakerStatus.Visible = true;
     }
 }
Example #27
0
 public int Play()
 {
     try
     {
         if (wmp.controls.currentItem != null)
         {
             wmp.controls.stop();
             wmp.close();
             wmp.controls.play();
             return(0);
         }
         else
         {
             return(1);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #28
0
        void ISoundNotificationPlayer.Play(string file)
        {
            wasTryingToPlay = true;

            try{
                if (player.URL != file)
                {
                    player.close();
                    player.URL          = file;
                    ignorePlaybackError = false;
                }
                else
                {
                    player.controls.stop();
                }

                player.controls.play();
            }catch (Exception e) {
                OnNotificationSoundError("An error occurred in Windows Media Player: " + e.Message);
            }
        }
Example #29
0
 //폼 꺼질 때(리소스 해제)
 private void mainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         playerInstance.close();
     }
     catch (Exception) { }
     try
     {
         progressThread.Abort();
     }
     catch (Exception) { }
 }
Example #30
0
        private Hashtable getMediaInfo(string in_path)
        {
            Hashtable ht = new Hashtable();

            IWMPMedia imed = mp.newMedia(in_path);

            for (int z = 0; z < imed.attributeCount; z++)
            {
                ht.Add(imed.getAttributeName(z), imed.getItemInfo(imed.getAttributeName(z)));
            }
            mp.close();
            return(ht);
        }
Example #31
0
        public List <RPMusicAlbum> GetAllAlbums()
        {
            if (!Settings.Default.EnableMusicLibrary)
            {
                return(new List <RPMusicAlbum>());
            }

            WindowsMediaPlayer   WMPlayer = new WindowsMediaPlayer();
            List <RPMusicAlbum>  output   = new List <RPMusicAlbum>();
            IWMPStringCollection scAlbums = WMPlayer.mediaCollection.getAttributeStringCollection("AlbumID", "Audio");

            for (int i = 0; i < scAlbums.count; i++)
            {
                if (string.IsNullOrEmpty(scAlbums.Item(i)))
                {
                    continue;                                         // avoid null strings
                }
                RPMusicAlbum album = new RPMusicAlbum();
                album.ID = scAlbums.Item(i);

                // Find a song in this album
                IWMPPlaylist pl = WMPlayer.mediaCollection.getByAttribute("AlbumID", album.ID);
                if (pl.count < 1)
                {
                    continue;                    // don't add the album; no matching media items  (must be an error, shouldn't happen)
                }
                IWMPMedia song = pl.get_Item(0); // just use the first song to get the additional album info

                // ALBUM ARTIST: Try to use the song property's "album artist", if this doesn't work, use the first song's author
                album.ArtistID = song.getItemInfo("WM/AlbumArtist");
                if (string.IsNullOrEmpty(album.ArtistID))
                {
                    album.ArtistID = song.getItemInfo("Author");
                }

                album.Title   = song.getItemInfo("WM/AlbumTitle");
                album.GenreID = song.getItemInfo("Genre");

                output.Add(album);
            }

            WMPlayer.close();

            // Sort output A-Z
            CommonEPG.Comparers.RPMusicAlbumNameComparer myComparer = new CommonEPG.Comparers.RPMusicAlbumNameComparer();
            output.Sort(myComparer);

            return(output);
        }
Example #32
0
        public List<RPMusicAlbum> GetAllAlbums()
        {
            if (!Settings.Default.EnableMusicLibrary) return new List<RPMusicAlbum>();

            WindowsMediaPlayer WMPlayer = new WindowsMediaPlayer();
            List<RPMusicAlbum> output = new List<RPMusicAlbum>();
            IWMPStringCollection scAlbums = WMPlayer.mediaCollection.getAttributeStringCollection("AlbumID", "Audio");

            for (int i = 0; i < scAlbums.count; i++)
            {
                if (string.IsNullOrEmpty(scAlbums.Item(i))) continue; // avoid null strings

                RPMusicAlbum album = new RPMusicAlbum();
                album.ID = scAlbums.Item(i);

                // Find a song in this album
                IWMPPlaylist pl = WMPlayer.mediaCollection.getByAttribute("AlbumID", album.ID);
                if (pl.count < 1) continue; // don't add the album; no matching media items  (must be an error, shouldn't happen)

                IWMPMedia song = pl.get_Item(0); // just use the first song to get the additional album info

                // ALBUM ARTIST: Try to use the song property's "album artist", if this doesn't work, use the first song's author
                album.ArtistID = song.getItemInfo("WM/AlbumArtist");
                if (string.IsNullOrEmpty(album.ArtistID))
                    album.ArtistID = song.getItemInfo("Author");

                album.Title = song.getItemInfo("WM/AlbumTitle");
                album.GenreID = song.getItemInfo("Genre");

                output.Add(album);
            }

            WMPlayer.close();

            // Sort output A-Z
            CommonEPG.Comparers.RPMusicAlbumNameComparer myComparer = new CommonEPG.Comparers.RPMusicAlbumNameComparer();
            output.Sort(myComparer);

            return output;
        }
Example #33
0
        public List<RPMusicArtist> GetAllArtists()
        {
            if (!Settings.Default.EnableMusicLibrary) return new List<RPMusicArtist>();

            WindowsMediaPlayer WMPlayer = new WindowsMediaPlayer();

            List<RPMusicArtist> output = new List<RPMusicArtist>();
            List<RPMusicArtist> outputList = new List<RPMusicArtist>();
            IWMPStringCollection scArtists = WMPlayer.mediaCollection.getAttributeStringCollection("Author", "Audio");

            for (int i = 0; i < scArtists.count; i++)
            {
                string strArtistName = scArtists.Item(i);
                if (string.IsNullOrEmpty(strArtistName)) continue; // Believe it or not WMP sometimes returns an empty artist name

                RPMusicArtist artist = new RPMusicArtist(strArtistName);
                output.Add(artist);
            }

            WMPlayer.close();

            // Sort output A-Z
            CommonEPG.Comparers.RPMusicArtistNameComparer myComparer = new CommonEPG.Comparers.RPMusicArtistNameComparer();
            output.Sort(myComparer);

            return output;
        }
Example #34
0
        public List<RPMusicGenre> GetAllGenres()
        {
            if (!Settings.Default.EnableMusicLibrary) return new List<RPMusicGenre>();

            WindowsMediaPlayer WMPlayer = new WindowsMediaPlayer();
            List<RPMusicGenre> output = new List<RPMusicGenre>();

            IWMPStringCollection scGenres = WMPlayer.mediaCollection.getAttributeStringCollection("Genre", "Audio");

            for (int i = 0; i < scGenres.count; i++)
            {
                RPMusicGenre genre = new RPMusicGenre(scGenres.Item(i));
                output.Add(genre);
            }

            WMPlayer.close();

            // Sort output A-Z
            CommonEPG.Comparers.RPMusicGenreTitleComparer myComparer = new CommonEPG.Comparers.RPMusicGenreTitleComparer();
            output.Sort(myComparer);

            return output;
        }
        public byte[] GetAlbumArtByTrack(Track track)
        {
            WindowsMediaPlayer mediaPlayer = null;
            byte[] imageData = null;

            try
            {
                mediaPlayer = new WindowsMediaPlayer();
                IWMPPlaylist foundTracks = mediaPlayer.mediaCollection.getByName(track.Title);
                string collectionId = string.Empty;
                string albumId = string.Empty;

                //LogUtility.LogMessage("Found " + foundTracks.count + " tracks matching title " + track.Title);
                for (int i = 0; i < foundTracks.count; i++)
                {
                    IWMPMedia foundTrack = foundTracks.get_Item(i);
                    if (track.FilePath == foundTrack.sourceURL)
                    {
                        //LogUtility.LogMessage("Found a track with sourceURL matching filepath");
                        collectionId = foundTrack.getItemInfo(MediaAttributes.WMWMCollectionID);
                        albumId = foundTrack.getItemInfo(MediaAttributes.AlbumID);

                        if (!ThumbnailCache.TryGetThumbnail(albumId, out imageData))
                        {
                            imageData = GetTrackArt(mediaPlayer, foundTrack, collectionId);
                            if (imageData != null)
                            {
                                break;
                            }
                        }
                    }
                }

                return imageData;

            }
            catch (Exception ex)
            {
                LogUtility.LogException(ex);
                throw;
            }
            finally
            {
                if (mediaPlayer != null)
                {
                    mediaPlayer.close();
                }
            }
        }
        public byte[] GetAlbumArtByAlbum(Album album)
        {
            WindowsMediaPlayer mediaPlayer = null;
            byte[] imageData = null;

            try
            {
                mediaPlayer = new WindowsMediaPlayer();
                IWMPPlaylist foundTracks = mediaPlayer.mediaCollection.getByAttribute(MediaAttributes.AlbumID, album.ID);
                string collectionId = string.Empty;
                string albumId = string.Empty;

                if (foundTracks.count == 0)
                {
                    return null;
                }

                IWMPMedia foundTrack = foundTracks.get_Item(0);
                collectionId = foundTrack.getItemInfo(MediaAttributes.WMWMCollectionID);
                albumId = foundTrack.getItemInfo(MediaAttributes.AlbumID);

                if (!ThumbnailCache.TryGetThumbnail(albumId, out imageData))
                {
                    imageData = GetTrackArt(mediaPlayer, foundTrack, collectionId);
                }

                return imageData;
            }
            catch (Exception ex)
            {
                LogUtility.LogException(ex);
                throw;
            }
            finally
            {
                if (mediaPlayer != null)
                {
                    mediaPlayer.close();
                }
            }
        }
        private IEnumerable<Track> getTracksByArtist(string artistName, bool isAlbumArtist)
        {
            List<Track> returnedTracks = new List<Track>();
            WindowsMediaPlayer mediaPlayer = null;

            try
            {
                mediaPlayer = new WindowsMediaPlayer();

                IWMPPlaylist trackPlaylist = null;
                if (isAlbumArtist)
                {
                    trackPlaylist = mediaPlayer.mediaCollection.getByAttribute(MediaAttributes.WMAlbumArtist, artistName);
                }
                else
                {
                    trackPlaylist = mediaPlayer.mediaCollection.getByAttribute(MediaAttributes.DisplayArtist, artistName);
                }

                for (int i = 0; i < trackPlaylist.count; i++)
                {
                    IWMPMedia track = trackPlaylist.get_Item(i);
                    returnedTracks.Add(track.GetTrack());
                }

                return returnedTracks;
            }
            catch (Exception ex)
            {
                LogUtility.LogException(ex);
                throw;
            }
            finally
            {
                if (mediaPlayer != null)
                {
                    mediaPlayer.close();
                }
            }
        }
        private IEnumerable<Album> getAlbumsByArtist(string artistName, bool isAlbumArtist)
        {
            WindowsMediaPlayer mediaPlayer = null;

            try
            {
                mediaPlayer = new WindowsMediaPlayer();
                return getAlbumsByArtist(mediaPlayer, artistName, isAlbumArtist);
            }
            catch (Exception ex)
            {
                LogUtility.LogException(ex);
                throw;
            }
            finally
            {
                if (mediaPlayer != null)
                {
                    mediaPlayer.close();
                }
            }
        }
Example #39
0
        public string FileNameForWMPItem(string itemTrackingID)
        {
            WindowsMediaPlayer WMPlayer = new WindowsMediaPlayer();
            IWMPPlaylist pl = WMPlayer.mediaCollection.getByAttribute("TrackingID", itemTrackingID);
            if (pl.count == 0)
            {
                Functions.WriteLineToLogFile("Warning - no item found in library with ID " + itemTrackingID);
                return null;
            }

            if (pl.count != 1) Functions.WriteLineToLogFile("Warning - more than one item found in library with ID " + itemTrackingID);

            IWMPMedia mItem = pl.get_Item(0);

            WMPlayer.close();
            return mItem.sourceURL;
        }
Example #40
0
        public List<RPMusicSong> GetSongsForGenre(string genreID)
        {
            if (!Settings.Default.EnableMusicLibrary) return new List<RPMusicSong>();

            WindowsMediaPlayer WMPlayer = new WindowsMediaPlayer();
            List<RPMusicSong> output = new List<RPMusicSong>();

            // Find all songs by this artist
            IWMPPlaylist pl = WMPlayer.mediaCollection.getByAttribute("Genre", genreID);
            for (int s = 0; s < pl.count; s++)
            {
                IWMPMedia song = pl.get_Item(s);

                RPMusicSong RPsong = CreateRPMusicSongFromIWMPMediaSong(song);
                if (RPsong != null) output.Add(RPsong);
            }

            WMPlayer.close();
            return output;
        }
        public IEnumerable<Track> GetTracks(Album album)
        {
            List<Track> returnedTracks = new List<Track>();
            WindowsMediaPlayer mediaPlayer = null;

            try
            {
                mediaPlayer = new WindowsMediaPlayer();

                IWMPPlaylist albumTracks = mediaPlayer.mediaCollection.getByAttribute(MediaAttributes.AlbumID, album.ID);

                for (int i = 0; i < albumTracks.count; i++)
                {
                    IWMPMedia trackMedia = albumTracks.get_Item(i);
                    returnedTracks.Add(trackMedia.GetTrack());
                }

                return returnedTracks;
            }
            catch (Exception ex)
            {
                LogUtility.LogException(ex);
                throw;
            }
            finally
            {
                if (mediaPlayer != null)
                {
                    mediaPlayer.close();
                }
            }
        }
Example #42
0
        /// <summary>
        /// Adds a file to the Windows Media Player (WMP) library
        /// </summary>
        /// <param name="filePath">File path and name</param>
        /// <returns>True if successful, false if unable to add</returns>
        public static bool AddFileToWMPLibrary(string filePath, Log jobLog)
        {
            WindowsMediaPlayer wmp = null;

            jobLog.WriteEntry("About to add " + filePath + " to the WMP library", Log.LogEntryType.Debug);

            try
            {
                wmp = new WindowsMediaPlayer(); // Create a new wmp object
                //wmp.uiMode = "invisible"; // Hide the window
                IWMPMediaCollection wmpLibrary = wmp.mediaCollection;

                IWMPMedia libStatus = wmpLibrary.add(filePath);
                if (libStatus == null || (((IWMPMedia2)libStatus).Error != null))
                    jobLog.WriteEntry("WARNING: Error adding file to WMP Library.\r\nError code : " + ((IWMPMedia2)libStatus).Error.errorCode.ToString() + ".\r\nError message : " + ((IWMPMedia2)libStatus).Error.errorDescription, Log.LogEntryType.Warning);
                else
                    jobLog.WriteEntry("Added " + filePath + " successfully to the WMP library", Log.LogEntryType.Information);

                // Release the COM object and clean up otherwise it hangs later
                wmp.close(); // Close the player
                Marshal.FinalReleaseComObject(wmp);
                wmp = null;
                return true;
            }
            catch (Exception e)
            {
                jobLog.WriteEntry("ERROR: Unable to communicate with WMP Library, WMP may not be installed. File not added to the WMP library.\r\nError : " + e.ToString(), Log.LogEntryType.Error);

                // Release the COM object
                if (wmp != null)
                {
                    wmp.close(); // Close the player
                    Marshal.FinalReleaseComObject(wmp);
                    wmp = null;
                }

                return false;
            }
        }
Example #43
0
        public Bitmap ThumbnailForWMPItem(string WMPMatchAttribute, string itemID, bool useFolderArtIfFound, Thumbnail_Sizes size, out string MimeType)
        {
            // Get URL
            MimeType = "";
            string picFileName;
            WindowsMediaPlayer WMPlayer = new WindowsMediaPlayer();

            IWMPPlaylist pl = WMPlayer.mediaCollection.getByAttribute(WMPMatchAttribute, itemID);
            if (pl.count == 0)
            {
                Functions.WriteLineToLogFile("Warning - no items found in library with ID " + itemID);
                return null;
            }

            //if (pl.count != 1) Functions.WriteLineToLogFile("Warning - more than one item found in library with ID " + itemID);

            IWMPMedia pic = pl.get_Item(0);

            picFileName = pic.sourceURL;

            WMPlayer.close();

            if (useFolderArtIfFound)
            {
                string itemFolder = Path.GetDirectoryName(picFileName);
                string folderArtFN = Path.Combine(itemFolder,"folder.jpg");
                if (File.Exists(folderArtFN))
                    picFileName = folderArtFN;
            }

            ShellHelper shellHelper = new ShellHelper();
            MimeType = "image/jpeg";
            string strLog = ""; // ignore
            switch (size)
            {
                case Thumbnail_Sizes.Small:
                    return shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Small, ref strLog);

                case Thumbnail_Sizes.Medium:
                    return shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Medium, ref strLog);

                case Thumbnail_Sizes.Large:
                    return shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Large, ref strLog);

                case Thumbnail_Sizes.ExtraLarge:
                    return shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.ExtraLarge, ref strLog);

                default:
                    return shellHelper.ThumbnailForFile(picFileName, ThumbnailSizes.Small, ref strLog);
            }
        }