C# MediaElement没有';我不能放声音

C# MediaElement没有';我不能放声音,c#,windows-phone-7,windows-phone-8,windows-phone,isolatedstorage,C#,Windows Phone 7,Windows Phone 8,Windows Phone,Isolatedstorage,我下载一个声音,并使用.mp3扩展名保存,如下所示: var response = await client.GetStreamAsync(fileUrl); using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(filePath, FileMode.Create, isolatedStorage)) { using (BinaryWriter binaryWriter = new Bin

我下载一个声音,并使用
.mp3
扩展名保存,如下所示:

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();
}

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

您不应该在SetSource()之后立即调用Play()。您应该钩住MediaOpened事件,并在MedaiOpened事件处理程序中调用Play()。

是否报告了任何错误或异常?请确保您已订阅了
MediaOpened
MediaFailed
事件,以确认它开始播放,并且您听到了任何错误。谢谢,在我的Windows应用商店应用程序中为我做了这个小动作-没有任何错误,声音也不会播放,因此这非常有用。