如何从手机和SD卡中获取音频文件并进行播放? 我只是一名设计师,但是当我看到代码时,我理解代码。
所以我需要的是一个代码就是这样。
答案 0 :(得分:0)
Petzold向我们展示了这一点。按下按钮,从库中随机播放曲调。
XAML:
<Button Content="Button" HorizontalAlignment="Left" Margin="177,160,0,0" VerticalAlignment="Top"/>
C#代码背后:
使用Microsoft.Xna.Framework.Media;
private void Button_Click(object sender, RoutedEventArgs e)
{
Random random = new Random(); // new random variable
MediaLibrary mediaLib = new MediaLibrary(); // this is where it grabs your whole music library and enumerates everything. If you break here, you can see it.
AlbumCollection albums = mediaLib.Albums; // pick which song you want.
Album album = albums[random.Next(albums.Count)];
SongCollection songs = mediaLib.Songs;
Song song = songs[random.Next(songs.Count)];
MediaPlayer.Play(song); // this plays the song.
}
就这么简单。