示例#1
0
 public void Play()
 {
     if (this.state == MonitorState.Started)
     {
         try {
             if (wmp.currentMedia == null)
             {
                 IWMPPlaylistArray plsArr = wmp.playlistCollection.getAll();                         // todo allow name specification
                 if (plsArr.count > 0)
                 {
                     wmp.currentPlaylist = plsArr.Item(0);
                 }
                 else
                 {
                     wmp.currentPlaylist = wmp.mediaCollection.getAll();
                 }
             }
             wmp.controls.play();
         }
         catch (COMException) {
             // application is busy... nothing we can do... just wait, when it will become available again
         }
         catch (Exception e) {
             this.Stop();
             errorMessage = "Error on Play: " + e.Message;
             state        = MonitorState.Interrupted;
         }
     }
 }
示例#2
0
 public VoicePlayer()
 {
     Mouth.Load();
     Ear.Load();
     pl = p.playlistCollection.getAll();
     p.settings.volume = 20;
     playall           = false;
     i = 0;
     loadSongs();
 }
示例#3
0
        private void DeletePlaylistToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IWMPPlaylist playlistForDeletion = MediaPlayer.playlistCollection.getByName(libraryListBox.GetItemText(libraryListBox.SelectedItem)).Item(0); // find playlist for deletion

            MediaPlayer.playlistCollection.remove(playlistForDeletion);                                                                                   // delete selected playlist

            MediaPlayer.close();
            MediaPlayer.currentPlaylist.clear();
            libraryListBox.Items.Clear();
            playlistListBox.Items.Clear();
            playListLabel.Text = "Unsaved Playlist";
            IWMPPlaylistArray allPlaylists = MediaPlayerHelper.SetupLibrary(libraryListBox, MediaPlayer); // refresh libarary
        }
示例#4
0
        /// <summary>
        /// Loads all of the users music into a playlist and sets it as the current. If
        /// no such playlist can be found or created, then return false.
        /// </summary>
        public bool LoadAllMusicPlaylist()
        {
            // Get an interface to the first playlist from the library.
            IWMPPlaylistArray playlists = _mediaPlayer.playlistCollection.getByName("All Music");

            if (playlists.count > 0)
            {
                // Make the retrieved playlist the current playlist.
                _mediaPlayer.currentPlaylist = playlists.Item(0);
                return(true);
            }

            return(false);
        }
示例#5
0
        public static IWMPPlaylist GetWMPPlaylist(WindowsMediaPlayer player, string playlistName)
        {
            IWMPPlaylist      returnPlaylist = null;
            IWMPPlaylistArray playlistArray  = player.playlistCollection.getByName(playlistName);

            if (playlistArray.count > 0)
            {
                returnPlaylist = playlistArray.Item(0);
            }
            else
            {
                // non existing, create it
                returnPlaylist = player.playlistCollection.newPlaylist(playlistName);
            }
            return(returnPlaylist);
        }
示例#6
0
        /// <summary>
        /// Adds the downloaded item to a playlist in Windows Media Player.
        /// </summary>
        /// <remarks>The title of the playlist is the name of the feed in RSS Bandit.</remarks>
        /// <param name="podcast"></param>
        private void AddPodcastToWMP(DownloadItem podcast)
        {
            try
            {
                if (!IsWMPFile(Path.GetExtension(podcast.File.LocalName)))
                {
                    return;
                }

                string     playlistName = Preferences.SinglePlaylistName;
                FeedSource source       = guiMain.FeedSourceOf(podcast.OwnerFeedId);

                if (!Preferences.SinglePodcastPlaylist && source != null)
                {
                    playlistName = source.GetFeeds()[podcast.OwnerFeedId].title;
                }

                WindowsMediaPlayer wmp = new WindowsMediaPlayer();

                //get a handle to the playlist if it exists or create it if it doesn't
                IWMPPlaylist      podcastPlaylist = null;
                IWMPPlaylistArray playlists       = wmp.playlistCollection.getAll();

                for (int i = 0; i < playlists.count; i++)
                {
                    IWMPPlaylist pl = playlists.Item(i);

                    if (pl.name.Equals(playlistName))
                    {
                        podcastPlaylist = pl;
                    }
                }

                if (podcastPlaylist == null)
                {
                    podcastPlaylist = wmp.playlistCollection.newPlaylist(playlistName);
                }

                IWMPMedia wm = wmp.newMedia(Path.Combine(podcast.TargetFolder, podcast.File.LocalName));
                podcastPlaylist.appendItem(wm);
            }
            catch (Exception e)
            {
                _log.Error("The following error occured in AddPodcastToWMP(): ", e);
            }
        }
示例#7
0
        public int addPlaylists(IWMPPlaylistCollection playlistCollection, IWMPPlaylistArray list)
        {
            ArrayList items = new ArrayList();

            for (int j = 0; j < list.count; j++)
            {
                bool         containsAudio = false;
                IWMPPlaylist playlist      = list.Item(j);
                string       name          = playlist.name;

                if (!name.Equals("All Music") && !name.Contains("TV") && !name.Contains("Video") && !name.Contains("Pictures"))
                {
                    for (int k = 0; k < playlist.count; k++)
                    {
                        try
                        {
                            if (playlist.get_Item(k).getItemInfo("MediaType").Equals("audio") && !playlistCollection.isDeleted(playlist))
                            {
                                containsAudio = true;
                            }
                        }
                        catch (Exception)
                        {
                            //Ignore playlists with invalid items
                        }
                    }
                }

                if (containsAudio)
                {
                    Playlist playlistData = new Playlist(name, stats_only);
                    if (!items.Contains(playlistData))
                    {
                        items.Add(playlistData);
                    }
                }
            }
            items.TrimToSize();
            if (!stats_only)
            {
                playlists = items;
            }
            return(items.Count);
        }
示例#8
0
        /// <summary>
        /// Sets up Library
        /// </summary>
        /// <param name="libraryListBox">library listbox</param>
        /// <param name="player">Media Player</param>
        /// <returns>playlist array</returns>
        public static IWMPPlaylistArray SetupLibrary(ListBox libraryListBox, AxWindowsMediaPlayer player)
        {
            IWMPPlaylistArray playlists = player.playlistCollection.getAll();

            for (int i = 0; i < playlists.count; i++)
            {
                try
                {
                    if (playlists.Item(i) != null && playlists.Item(i).getItemInfo("PlaylistType") == "wpl") // retrives playlist
                    {
                        libraryListBox.Items.Add(playlists.Item(i).name);
                    }
                }
                catch (System.IO.FileNotFoundException)
                {
                    // skip playlists that have been deleted
                }
            }

            return(playlists);
        }
示例#9
0
        private IWMPPlaylist GeneratePlaylist()
        {
            IWMPPlaylistArray playlists = _player.playlistCollection.getByName(nameof(MusicPlayer));
            IWMPPlaylist      playlist;

            if (playlists.count > 1)
            {
                playlist = playlists.Item(0);
                playlist.clear();
            }
            else
            {
                playlist = _player.playlistCollection.newPlaylist(nameof(MusicPlayer));
            }

            foreach (var file in Directory.EnumerateFiles(General.Instance.MusicFolder, "*.mp3"))
            {
                IWMPMedia media = _player.newMedia(file);
                playlist.appendItem(media);
            }

            return(playlist);
        }
示例#10
0
            public int addPlaylists(IWMPPlaylistCollection playlistCollection, IWMPPlaylistArray list)
            {
                int result_count = 0;
                for (int j = 0; j < list.count; j++)
                {
                    bool containsAudio = false;
                    IWMPPlaylist playlist = list.Item(j);
                    string name = playlist.name;

                    if (!name.Equals("All Music") && !name.Contains("TV") && !name.Contains("Video") && !name.Contains("Pictures"))
                    {
                        for (int k = 0; k < playlist.count; k++)
                        {
                            try
                            {
                                if (playlist.get_Item(k).getItemInfo("MediaType").Equals("audio") && !playlistCollection.isDeleted(playlist))
                                {
                                    containsAudio = true;
                                }
                            }
                            catch (Exception)
                            {
                                //Ignore playlists with invalid items
                            }
                        }
                    }

                    if (containsAudio)
                    {
                        if (!m_stats_only) playlists.Add(new Playlist(name));
                        else result_count++;
                    }
                }
                return result_count;
            }