media player in windows phone 7 displaying next song

扶醉桌前 提交于 2020-01-06 13:56:22

问题


I want to do something similar to the media player in windows phone 7 where the next several song is shown. What approach I would take to accomplish this?

Example: previous song previous song CURRENT SONG next song next song

my code currently like this:

        void MainPage_Loaded(object sender, RoutedEventArgs e)         
    {         
        List<string> songlist = new List<string>();         
        MediaLibrary library = new MediaLibrary();         
        mySongCollection = library.Songs;         
        MediaPlayer.ActiveSongChanged += new EventHandler<EventArgs>(MediaPlayer_ActiveSongChanged);         
        MediaPlayer.MediaStateChanged += new EventHandler<EventArgs>(MediaPlayer_MediaStateChanged);         

        UpdateCurrentSongInformation();         
    }         

    void UpdateCurrentSongInformation()         
    {         
        try         
        {
            MediaLibrary lb = new MediaLibrary();
            int i = MediaPlayer.Queue.ActiveSongIndex;

           textBlock1.Text= lb.Songs.ToString();

            txtAlbumName.Text = MediaPlayer.Queue.ActiveSong.Album.Name;         
            txtArtistName.Text = MediaPlayer.Queue.ActiveSong.Artist.Name;         
            txtSongName.Text = MediaPlayer.Queue.ActiveSong.Name;
            progressBar1.Maximum = MediaPlayer.Queue.ActiveSong.Duration.Minutes*60+MediaPlayer.Queue.ActiveSong.Duration.Seconds;
            double max = MediaPlayer.Queue.ActiveSong.Duration.Milliseconds;


            BitmapImage bmp = new BitmapImage();         
            bmp.SetSource(MediaPlayer.Queue.ActiveSong.Album.GetAlbumArt());

            imgAlbumCover.Source = bmp;         
        }         
        catch         
        {         
            imgAlbumCover.Source = null;         
        }         
    }

Like Dennis suggest, I code it like this:

            MediaLibrary lb = new MediaLibrary();
            int i = MediaPlayer.Queue.ActiveSongIndex;
            NextSong.Text = lb.Songs[i+1].Name;

回答1:


Since you have MediaPlayer.Queue.ActiveSongIndex, you can also access existing items in the queue by their index through MediaPlayer.Queue[n] where n is the song index. You will get a Song instance with the same metadata. As long as you have the current index, you can decrement it by one to check for the previous song, and increment it by one to check for the next song.



来源:https://stackoverflow.com/questions/6907081/media-player-in-windows-phone-7-displaying-next-song

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!