如何播放音乐库中的歌曲?我试过这个:
private void click_AlarmSet(object sender, RoutedEventArgs e)
{
play();
}
async private void play()
{
var openPicker = new Windows.Storage.Pickers.FileOpenPicker();
openPicker.SuggestedStartLocation =Windows.Storage.Pickers.PickerLocationId.MusicLibrary;
openPicker.FileTypeFilter.Add("toxic.mp3");
var file = await openPicker.PickSingleFileAsync();
var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
sound.SetSource(stream, file.ContentType);
sound.Play();
}
这里sound
是我的媒体元素,“toxic.mp3”是我要播放的mp3文件,但是mp3没有播放。
答案 0 :(得分:1)
openPicker.FileTypeFilter.Add("toxic.mp3")
我认为FileTypeFilter正在寻找“.mp3”或“.wav”而不是特定的文件名。 http://msdn.microsoft.com/en-us/library/windows.storage.pickers.fileopenpicker.filetypefilter.Aspx
建议:
var name = "toxic.mp3";
var file = await openPicker.GetFileAsync(name);
var stream = await file.OpenAsync(FileAccessMode.Read);
sound.SetSource(stream, file.ContentType);
- 或 - 如果你想要所有'.mp3'
openPicker.FileTypeFilter.Add(".mp3")