如何点击歌曲列表播放歌曲?

时间:2014-10-16 07:29:33

标签: windows-phone-8 media-player media-library

我的课程有一个媒体播放器项目。我有一个列表歌曲:

<ListBox Name="listBoxSongs" SelectionChanged="listBoxSongs_SelectionChanged">
            <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Image Width="100"  Margin="8" Source="{Binding Image}"/>
                            <StackPanel >
                                <TextBlock Foreground="{StaticResource PhoneAccentBrush}" Text="{Binding Title}"  TextWrapping="Wrap" FontSize="24" />
                                <TextBlock VerticalAlignment="Center"  Text="{Binding Artist}" TextWrapping="Wrap"/>
                            </StackPanel>
                            <TextBlock Margin="10" HorizontalAlignment="Left" VerticalAlignment="Center" Text="{Binding Duration}" />
                        </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

以下代码使用媒体库并显示带有listview的歌曲列表:

 foreach (Song song in songs)
        {
            if (song != null)
                mySongs.Add(new MySongs()
                {
                    Artist = song.Artist.ToString(),
                    Title = song.Name,
                    Duration = (new DateTime(song.Duration.Ticks)).ToString("mm:ss")
                });
            else
            {

                TextBlock msg = new TextBlock();

                msg.Text = "no music";
                listBoxSongs.Items.Add(msg);
            }
            if (song.Album.HasArt)
            {
                BitmapImage img = new BitmapImage();

                img.SetSource(song.Album.GetAlbumArt());
                mySongs.Last().Image = img;
            }
            else
                mySongs.Last().Image = new BitmapImage(new Uri("Images/noArt.png", UriKind.Relative));
        }

        listBoxSongs.ItemsSource = mySongs;

如何导航到&#34; mainPage.xaml&#34;当我点击listview项目时,从我的列表中播放一首歌?

0 个答案:

没有答案