0

我下载一个声音,并与.mp3扩展这样的保存:的MediaElement不播放声音

var response = await client.GetStreamAsync(fileUrl); 

using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(filePath, FileMode.Create, isolatedStorage)) 
{ 
    using (BinaryWriter binaryWriter = new BinaryWriter(fileStream)) 
    { 
     await response.CopyToAsync(fileStream); 
    } 
} 

现在,当我看向IsolatedStorage由独立存储浏览器,我看到那里的文件,我可以玩它也。

我要访问并播放:

IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication(); 

IsolatedStorageFileStream fileStream = isolatedStorage.OpenFile(filePath, FileMode.Open, FileAccess.Read); 

musicMediaElement.SetSource(fileStream); 
musicMediaElement.Play(); 
} 

我什么也没听到。我不知道我做错了什么。

+0

是否报告了任何错误或异常?确保您订阅了“MediaOpened”和“MediaFailed”事件以确认它开始播放,并且您听到任何错误消息。 –

回答

1

您不应该在SetSource()之后立即调用Play()。您应该挂接MediaOpened事件,并在MedaiOpened事件处理函数中调用Play()。

+0

谢谢,在我的Windows应用程序应用程序中为我做了诀窍 - 没有得到任何错误,声音也不会播放,所以这真的很有帮助。 – Gorgsenegger