Jap*_*Jap 5 c# audio wpf wpf-controls windows-phone-8
我正在创建一个具有播放功能的录音机控件.
我使用media元素播放录制的音频,如下所示:
using (var storage = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
{
using (System.IO.Stream stream = new System.IO.IsolatedStorage.IsolatedStorageFileStream(filePath, System.IO.FileMode.Open, storage))
{
player.SetSource(stream);
}
}
Run Code Online (Sandbox Code Playgroud)
我面临的问题是,当我使用媒体元素播放录制的音频时.流被锁定到媒体元素.我无法覆盖该文件,甚至无法再次播放该SetSource()
方法,因为该方法会抛出异常.
有没有办法强制媒体元素释放流?
基于@Sheridan回答这个问题,我想出了它的作用.
每当MediaElement
使用Stop()
函数停止时,将Source
Property 设置为null
:
ResetMediaElement()
{
mediaElement.Stop();
mediaElement.Source = null;
}
Run Code Online (Sandbox Code Playgroud)
这将关闭附加到media元素的流,以便相关资源可以在其他地方使用.