MediaElement不播放声音

时间:2013-09-25 17:42:15

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

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

1 个答案:

答案 0 :(得分:1)

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

相关问题