Beispiel #1
0
        public void initPath()
        {
            player.windowlessVideo = true;//双击全屏
            //listBox1.Items.Clear();  //清空控件
            string        url    = "H:/网易云音乐下载";
            DirectoryInfo folder = new DirectoryInfo(url);

            foreach (FileInfo file in folder.GetFiles("*.mp3"))
            {
                WMPLib.IWMPMedia media = player.newMedia(file.FullName);
                player.currentPlaylist.appendItem(media);
                double time   = media.duration;
                String author = media.getItemInfo("Author");;
                String title  = media.getItemInfo("Title");
                Song   song   = new Song(title, file.FullName, author, (long)time, sign);
                songList.Add(song);
                listBox1.Items.Add("  " + author + "             " + title + "            " + time);
            }
        }
Beispiel #2
0
 private void ButInfo_Click(object sender, EventArgs e)
 {
     if (this.optFile.FileName != "optFile")       //当打开文件的文件名不为“optFile”
     {
         c = new WMPLib.WindowsMediaPlayerClass(); //实例化WindowsMediaPlayerClass类的对象
         m = c.newMedia(this.optFile.FileName);    //为IWMPMedia对象赋值
         //获取媒体详细信息
         MessageBox.Show("歌手名:" + m.getItemInfo("Author") + "\r\n" + "歌  名:" + m.getItemInfo("Title"));
     }
 }
        /// <summary>
        /// Executes the specified param.
        /// </summary>
        /// <param name="param">The param.</param>
        /// <param name="result">The result.</param>
        /// <returns></returns>
        public OpResult Execute(string param)
        {
            OpResult opResult = new OpResult();
            bool     bFirst   = !queue;
            bool     bByIndex = false;
            int      idx      = 0;

            opResult.StatusCode = OpStatusCode.Ok;
            try
            {
                if (Player == null)
                {
                    Player = new WMPLib.WindowsMediaPlayer();
                }

                if (param.IndexOf("-help") >= 0)
                {
                    opResult = showHelp(opResult);
                    return(opResult);
                }

                DateTime startTime = DateTime.Now;

                // Use custom format?
                Match custom_match = custom_regex.Match(param);
                if (custom_match.Success)
                {
                    showWhat = System.Convert.ToInt32(custom_match.Groups["index"].Value, 10);
                    param    = custom_match.Groups["remainder"].Value;
                }

                Match match = index_regex.Match(param);
                if (match.Success)
                {
                    idx      = System.Convert.ToInt32(match.Groups["index"].Value, 10);
                    bByIndex = true;
                    param    = "";
                }
                else
                {
                    idx   = 0;
                    param = param.ToLower();
                }

                if (showWhat == 0)
                {
                    opResult = listArtistsOnly(opResult, param);
                    TimeSpan duration = DateTime.Now - startTime;
                    opResult.AppendFormat("elapsed_time={0}", duration.TotalSeconds);
                    return(opResult);
                }
                if (param.Length > 0)
                {
                    mediaPlaylist = byArtist(param);
                }
                else
                {
                    mediaPlaylist = Player.mediaCollection.getByAttribute("MediaType", "Audio");
                }

                bool bArtistMatch = false;
                the_state.init();

                int iCount = mediaPlaylist.count;

                string keyArtist = "";
                string keyAlbum  = "";

                // Header:
                templateOut(String.Format("{0}H", showWhat), opResult, 0, -1);

                for (int x = idx; x < iCount; x++)
                {
                    media = mediaPlaylist.get_Item(x);
                    the_state.nextArtist = media.getItemInfo("WM/AlbumArtist");
                    if (the_state.nextArtist == "")
                    {
                        the_state.nextArtist = media.getItemInfo("Author");
                    }
                    the_state.nextAlbum = media.getItemInfo("WM/AlbumTitle");
                    if (bByIndex && x == idx)
                    {
                        keyArtist = the_state.nextArtist;
                        keyAlbum  = the_state.nextAlbum;
                    }
                    else
                    {
                        if (showBy == by_track && keyArtist.Length > 0 && x != idx)
                        {
                            break;
                        }
                        if (showBy == by_artist && keyArtist.Length > 0 && the_state.nextArtist != keyArtist)
                        {
                            break;
                        }
                        if (showBy == by_album && keyArtist.Length > 0 && (the_state.nextAlbum != keyAlbum || the_state.nextArtist != keyArtist))
                        {
                            break;
                        }
                    }

                    if (the_state.nextArtist != the_state.artist) // New artist?
                    {
                        if (bArtistMatch)                         // Did last artist match?
                        {
                            // Close album:
                            if (the_state.album.Length > 0)
                            {
                                if (!templateOut(String.Format("{0}.{1}-", showWhat, show_albums), opResult, x, -1) && ((showWhat & show_albums) != 0) && the_state.albumTrackCount > 0)
                                {
                                    opResult.AppendFormat("    Album_song_count: {0}", the_state.albumTrackCount);
                                }
                            }
                            the_state.resetAlbum();
                            // Close artist"
                            if (!templateOut(String.Format("{0}.{1}-", showWhat, show_artists), opResult, x, -1))
                            {
                                if (the_state.artistAlbumCount > 0)
                                {
                                    opResult.AppendFormat("  Artist_album_count: {0}", the_state.artistAlbumCount);
                                }
                                if (the_state.artistTrackCount > 0)
                                {
                                    opResult.AppendFormat("  Artist_song_count: {0}", the_state.artistTrackCount);
                                }
                            }
                            the_state.resetArtist();
                        }
                        if (the_state.nextArtist.ToLower().StartsWith(param))
                        {
                            bArtistMatch           = true;
                            the_state.artistCount += 1;

                            the_state.artistIndex = x;

                            if (keyArtist.Length <= 0)
                            {
                                keyArtist = the_state.nextArtist;
                                keyAlbum  = the_state.nextAlbum;
                            }
                        }
                        else
                        {
                            bArtistMatch = false;
                        }
                        the_state.artist = the_state.nextArtist;
                        if (bArtistMatch)
                        {
                            // Open Artist
                            if (!templateOut(String.Format("{0}.{1}+", showWhat, show_artists), opResult, x, -1) && ((showWhat & show_artists) != 0))
                            {
                                opResult.AppendFormat("Artist:<{0}> \"{1}\"", x, the_state.artist);
                            }
                        }
                    }
                    if (bArtistMatch)
                    {
                        the_state.artistTrackCount += 1;
                        the_state.trackCount       += 1;
                        if (the_state.nextAlbum != the_state.album)
                        {
                            if (the_state.album.Length > 0)
                            {
                                // Close album
                                if (!templateOut(String.Format("{0}.{1}-", showWhat, show_albums), opResult, x, -1) && ((showWhat & show_albums) != 0) && the_state.albumTrackCount > 0)
                                {
                                    opResult.AppendFormat("    Album_song_count: {0}", the_state.albumTrackCount);
                                }
                            }
                            the_state.resetAlbum();
                            the_state.album = the_state.nextAlbum;
                            if (the_state.nextAlbum.Length > 0)
                            {
                                the_state.albumIndex        = x;
                                the_state.albumCount       += 1;
                                the_state.artistAlbumCount += 1;
                                the_state.albumList_add(the_state.nextAlbum);
                                the_state.albumYear  = media.getItemInfo("WM/Year");
                                the_state.albumGenre = media.getItemInfo("WM/Genre");
                                the_state.findAlbumCover(media.sourceURL);
                                // Open album
                                if (!templateOut(String.Format("{0}.{1}+", showWhat, show_albums), opResult, x, -1) && ((showWhat & show_albums) != 0))
                                {
                                    opResult.AppendFormat("  Album:<{0}> \"{1}\"", x, the_state.nextAlbum);
                                }
                            }
                        }
                        the_state.album            = the_state.nextAlbum;
                        the_state.albumTrackCount += 1;
                        the_state.song             = media.getItemInfo("Title");
                        the_state.songLocation     = media.sourceURL;
                        the_state.songTrackNumber  = media.getItemInfo("WM/TrackNumber");
                        the_state.songLength       = media.durationString;
                        if (the_state.albumYear == "" || the_state.albumYear.Length < 4)
                        {
                            the_state.albumYear = media.getItemInfo("WM/OriginalReleaseYear");
                        }
                        the_state.albumGenre_add(media.getItemInfo("WM/Genre"));
                        the_state.findAlbumCover(the_state.songLocation);

                        // Open / close song
                        if (!templateOut(String.Format("{0}.{1}-", showWhat, show_songs), opResult, x, -1) && ((showWhat & show_songs) != 0) && the_state.song.Length > 0)
                        {
                            opResult.AppendFormat("    Song:<{0}> \"{1}\" ({2})", x, the_state.song, the_state.songLength);
                        }
                        templateOut(String.Format("{0}.{1}+", showWhat, show_songs), opResult, x, -1);

                        // Play / queue song?
                        if (play)
                        {
                            PlayMediaCmd pmc;
                            pmc      = new PlayMediaCmd(MediaType.Audio, !bFirst);
                            bFirst   = false;
                            opResult = pmc.Execute(media.sourceURL);
                        }
                    }
                }
                if (play)
                {
                    opResult.AppendFormat("Queued {0} songs to play", the_state.trackCount);
                }
                else
                {
                    // Close album:
                    if (the_state.album.Length > 0)
                    {
                        if (!templateOut(String.Format("{0}.{1}-", showWhat, show_albums), opResult, the_state.trackCount, -1) && ((showWhat & show_albums) != 0) && the_state.albumTrackCount > 0)
                        {
                            opResult.AppendFormat("    Album_song_count: {0}", the_state.albumTrackCount);
                        }
                    }
                    the_state.resetAlbum();
                    // Close artist:
                    if (!templateOut(String.Format("{0}.{1}-", showWhat, show_artists), opResult, the_state.trackCount, -1))
                    {
                        if (the_state.artistAlbumCount > 0)
                        {
                            opResult.AppendFormat("  Artist_album_count: {0}", the_state.artistAlbumCount);
                        }
                        if (the_state.artistTrackCount > 0)
                        {
                            opResult.AppendFormat("  Artist_song_count: {0}", the_state.artistTrackCount);
                        }
                    }
                    the_state.resetArtist();
                }
                // Footer:
                TimeSpan elapsed_duration = DateTime.Now - startTime;
                if (!templateOut(String.Format("{0}F", showWhat), opResult, the_state.trackCount, elapsed_duration.TotalSeconds))
                {
                    if (the_state.artistCount > 0)
                    {
                        opResult.AppendFormat("Artist_count: {0}", the_state.artistCount);
                    }
                    if (the_state.albumCount > 0)
                    {
                        opResult.AppendFormat("Album_count: {0}", the_state.albumCount);
                    }
                    if (the_state.trackCount > 0)
                    {
                        opResult.AppendFormat("Song_count: {0}", the_state.trackCount);
                    }
                    opResult.AppendFormat("elapsed_time={0}", elapsed_duration.TotalSeconds);
                }
            }
            catch (Exception ex)
            {
                opResult.StatusCode = OpStatusCode.Exception;
                opResult.StatusText = ex.Message;
            }
            return(opResult);
        }
        /// <summary>
        /// Executes the specified param.
        /// </summary>
        /// <param name="param">The param.</param>
        /// <param name="result">The result.</param>
        /// <returns></returns>
        public OpResult Execute(string param)
        {
            OpResult opResult = new OpResult();
            bool bFirst = !queue;
            bool bByIndex = false;
            int idx = 0;

            opResult.StatusCode = OpStatusCode.Ok;
            try
            {
                if (Player == null) Player = new WMPLib.WindowsMediaPlayer();

                if (param.IndexOf("-help") >= 0)
                {
                    opResult = showHelp(opResult);
                    return opResult;
                }

                DateTime startTime = DateTime.Now;

                // Use custom format?
                Match custom_match = custom_regex.Match(param);
                if (custom_match.Success)
                {
                    showWhat = System.Convert.ToInt32(custom_match.Groups["index"].Value, 10);
                    param = custom_match.Groups["remainder"].Value;
                }

                Match match = index_regex.Match(param);
                if (match.Success)
                {
                    idx = System.Convert.ToInt32(match.Groups["index"].Value, 10);
                    bByIndex = true;
                    param = "";
                }
                else
                {
                    idx = 0;
                    param = param.ToLower();
                }

                if (showWhat == 0)
                {
                    opResult = listArtistsOnly(opResult, param);
                    TimeSpan duration = DateTime.Now - startTime;
                    opResult.AppendFormat("elapsed_time={0}", duration.TotalSeconds);
                    return opResult;
                }
                if (param.Length > 0) mediaPlaylist = byArtist(param);
                else mediaPlaylist = Player.mediaCollection.getByAttribute("MediaType", "Audio");

                bool bArtistMatch = false;
                the_state.init();

                int iCount = mediaPlaylist.count;

                string keyArtist = "";
                string keyAlbum = "";

                // Header:
                templateOut(String.Format("{0}H", showWhat), opResult, 0, -1);

                for (int x = idx; x < iCount; x++)
                {
                    media = mediaPlaylist.get_Item(x);
                    the_state.nextArtist = media.getItemInfo("WM/AlbumArtist");
                    if (the_state.nextArtist == "") the_state.nextArtist = media.getItemInfo("Author");
                    the_state.nextAlbum = media.getItemInfo("WM/AlbumTitle");
                    if (bByIndex && x == idx)
                    {
                        keyArtist = the_state.nextArtist;
                        keyAlbum = the_state.nextAlbum;
                    }
                    else
                    {
                        if (showBy == by_track && keyArtist.Length > 0 && x != idx) break;
                        if (showBy == by_artist && keyArtist.Length > 0 && the_state.nextArtist != keyArtist) break;
                        if (showBy == by_album && keyArtist.Length > 0 && (the_state.nextAlbum != keyAlbum || the_state.nextArtist != keyArtist)) break;
                    }

                    if (the_state.nextArtist != the_state.artist)   // New artist?
                    {
                        if (bArtistMatch) // Did last artist match?
                        {
                            // Close album:
                            if (the_state.album.Length > 0)
                            {
                                if (!templateOut(String.Format("{0}.{1}-", showWhat, show_albums), opResult, x, -1) && ((showWhat & show_albums) != 0) && the_state.albumTrackCount > 0)
                                    opResult.AppendFormat("    Album_song_count: {0}", the_state.albumTrackCount);
                            }
                            the_state.resetAlbum();
                            // Close artist"
                            if (!templateOut(String.Format("{0}.{1}-", showWhat, show_artists), opResult, x, -1))
                            {
                                if (the_state.artistAlbumCount > 0) opResult.AppendFormat("  Artist_album_count: {0}", the_state.artistAlbumCount);
                                if (the_state.artistTrackCount > 0) opResult.AppendFormat("  Artist_song_count: {0}", the_state.artistTrackCount);
                            }
                            the_state.resetArtist();
                        }
                        if (the_state.nextArtist.ToLower().StartsWith(param))
                        {
                            bArtistMatch = true;
                            the_state.artistCount += 1;

                            the_state.artistIndex = x;

                            if (keyArtist.Length <= 0)
                            {
                                keyArtist = the_state.nextArtist;
                                keyAlbum = the_state.nextAlbum;
                            }
                        }
                        else bArtistMatch = false;
                        the_state.artist = the_state.nextArtist;
                        if (bArtistMatch)
                        {
                            // Open Artist
                            if (!templateOut(String.Format("{0}.{1}+", showWhat, show_artists), opResult, x, -1) && ((showWhat & show_artists) != 0))
                                opResult.AppendFormat("Artist:<{0}> \"{1}\"", x, the_state.artist);
                        }
                    }
                    if (bArtistMatch)
                    {
                        the_state.artistTrackCount += 1;
                        the_state.trackCount += 1;
                        if (the_state.nextAlbum != the_state.album)
                        {
                            if (the_state.album.Length > 0)
                            {
                                // Close album
                                if (!templateOut(String.Format("{0}.{1}-", showWhat, show_albums), opResult, x, -1) && ((showWhat & show_albums) != 0) && the_state.albumTrackCount > 0)
                                    opResult.AppendFormat("    Album_song_count: {0}", the_state.albumTrackCount);
                            }
                            the_state.resetAlbum();
                            the_state.album = the_state.nextAlbum;
                            if (the_state.nextAlbum.Length > 0)
                            {
                                the_state.albumIndex = x;
                                the_state.albumCount += 1;
                                the_state.artistAlbumCount += 1;
                                the_state.albumList_add(the_state.nextAlbum);
                                the_state.albumYear = media.getItemInfo("WM/Year");
                                the_state.albumGenre = media.getItemInfo("WM/Genre");
                                the_state.findAlbumCover(media.sourceURL);
                                // Open album
                                if (!templateOut(String.Format("{0}.{1}+", showWhat, show_albums), opResult, x, -1) && ((showWhat & show_albums) != 0))
                                    opResult.AppendFormat("  Album:<{0}> \"{1}\"", x, the_state.nextAlbum);
                            }
                        }
                        the_state.album = the_state.nextAlbum;
                        the_state.albumTrackCount += 1;
                        the_state.song = media.getItemInfo("Title");
                        the_state.songLocation = media.sourceURL;
                        the_state.songTrackNumber = media.getItemInfo("WM/TrackNumber");
                        the_state.songLength = media.durationString;
                        if (the_state.albumYear == "" || the_state.albumYear.Length < 4) the_state.albumYear = media.getItemInfo("WM/OriginalReleaseYear");
                        the_state.albumGenre_add(media.getItemInfo("WM/Genre"));
                        the_state.findAlbumCover(the_state.songLocation);

                        // Open / close song
                        if (!templateOut(String.Format("{0}.{1}-", showWhat, show_songs), opResult, x, -1) && ((showWhat & show_songs) != 0) && the_state.song.Length > 0)
                            opResult.AppendFormat("    Song:<{0}> \"{1}\" ({2})", x, the_state.song, the_state.songLength);
                        templateOut(String.Format("{0}.{1}+", showWhat, show_songs), opResult, x, -1);

                        // Play / queue song?
                        if (play)
                        {
                            PlayMediaCmd pmc;
                            pmc = new PlayMediaCmd(MediaType.Audio, !bFirst);
                            bFirst = false;
                            opResult = pmc.Execute(media.sourceURL);
                        }
                    }
                }
                if (play) opResult.AppendFormat("Queued {0} songs to play", the_state.trackCount);
                else
                {
                    // Close album:
                    if (the_state.album.Length > 0)
                    {
                        if (!templateOut(String.Format("{0}.{1}-", showWhat, show_albums), opResult, the_state.trackCount, -1) && ((showWhat & show_albums) != 0) && the_state.albumTrackCount > 0)
                            opResult.AppendFormat("    Album_song_count: {0}", the_state.albumTrackCount);
                    }
                    the_state.resetAlbum();
                    // Close artist:
                    if (!templateOut(String.Format("{0}.{1}-", showWhat, show_artists), opResult, the_state.trackCount, -1))
                    {
                        if (the_state.artistAlbumCount > 0) opResult.AppendFormat("  Artist_album_count: {0}", the_state.artistAlbumCount);
                        if (the_state.artistTrackCount > 0) opResult.AppendFormat("  Artist_song_count: {0}", the_state.artistTrackCount);
                    }
                    the_state.resetArtist();
                }
                // Footer:
                TimeSpan elapsed_duration = DateTime.Now - startTime;
                if (!templateOut(String.Format("{0}F", showWhat), opResult, the_state.trackCount, elapsed_duration.TotalSeconds))
                {
                    if (the_state.artistCount > 0) opResult.AppendFormat("Artist_count: {0}", the_state.artistCount);
                    if (the_state.albumCount > 0) opResult.AppendFormat("Album_count: {0}", the_state.albumCount);
                    if (the_state.trackCount > 0) opResult.AppendFormat("Song_count: {0}", the_state.trackCount);
                    opResult.AppendFormat("elapsed_time={0}", elapsed_duration.TotalSeconds);
                }

            }
            catch (Exception ex)
            {
                opResult.StatusCode = OpStatusCode.Exception;
                opResult.StatusText = ex.Message;
            }
            return opResult;
        }
Beispiel #5
0
        private void viewToolStripMenuItem_Click(object sender, EventArgs e)
        {
            viewfileinfo view = new viewfileinfo();

            WMPLib.IWMPMedia media = axWindowsMediaPlayer1.newMedia(paths[listBox1.SelectedIndex]);
            view.attr[0]  = media.getItemInfo("Track").ToString();
            view.attr[1]  = media.getItemInfo("Disc").ToString();
            view.attr[2]  = media.getItemInfo("BPM").ToString();
            view.attr[3]  = media.name.ToString();
            view.attr[4]  = media.getItemInfo("Artist").ToString();
            view.attr[5]  = media.getItemInfo("Album").ToString();
            view.attr[6]  = media.getItemInfo("Album Artist").ToString();
            view.attr[7]  = media.getItemInfo("Year").ToString();
            view.attr[8]  = media.getItemInfo("Genre").ToString();
            view.attr[9]  = media.getItemInfo("Comment").ToString();
            view.attr[10] = media.getItemInfo("Composer").ToString();
            view.attr[11] = media.getItemInfo("Publisher").ToString();
            view.attr[12] = paths[listBox1.SelectedIndex];
            view.Show();
        }