Windows Phone 7中的媒体播放器显示下一首歌曲 [英] media player in windows phone 7 displaying next song

查看:88
本文介绍了Windows Phone 7中的媒体播放器显示下一首歌曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一些类似于Windows Phone 7中显示下几首歌曲的媒体播放器的操作.我将采取什么方法来实现这一目标?

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

我的代码当前如下:

        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;

推荐答案

由于您拥有MediaPlayer.Queue.ActiveSongIndex,因此您还可以通过MediaPlayer.Queue[n]通过其中的 n 索引来访问队列中的现有项目.歌曲索引.您将获得一个具有相同元数据的Song实例.只要具有当前索引,就可以将其递减一以检查上一首歌曲,并将其递增一以检查下一首歌.

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.

这篇关于Windows Phone 7中的媒体播放器显示下一首歌曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆