我試圖將所有音樂文件放入列表框並播放選定的文件。在Windows Phone 8.1上播放音樂
下面的代碼是我做的音樂播放,但不幸的是它不播放。誰能告訴我這個錯誤是什麼?
private async void button1_Click(object sender, RoutedEventArgs e)
{
StorageFolder folder = Windows.Storage.KnownFolders.MusicLibrary;
IReadOnlyList<StorageFile> files = await folder.GetFilesAsync();
foreach (var file in files)
{
MusicProperties music = await file.Properties.GetMusicPropertiesAsync();
listBox2.Items.Add(music.Title);
}
}
private async void listBox2_Tapped(object sender, TappedRoutedEventArgs e)
{
try
{
StorageFolder folder = Windows.Storage.KnownFolders.MusicLibrary;
IReadOnlyList<StorageFile> files = await folder.GetFilesAsync();
if (files.Count > 0)
{
var file = files[listBox2.SelectedIndex];
mediaElement1.Source = new Uri(files[listBox2.SelectedIndex].Path);
textBlock1.Text = files[listBox2.SelectedIndex].Path;
mediaElement1.Play();
}
}
catch(Exception ex)
{
textBlock1.Text = ex.Message;
}
}
我改變了你所說的代碼,但它仍然不起作用。 :( –
破解它最後 –
@Harishkutty你是怎麼破解它的?你能分享細節嗎? – asitis