强制的MediaElement在播放后释放流 [英] Forcing MediaElement to Release Stream after playback

查看:2067
本文介绍了强制的MediaElement在播放后释放流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建录音机控制,具有回放功能。

I am creating an audio recorder control, with playback functionality.

我用的媒体元素播放录制的音频是这样的:

I use the media element to play the recorded audio like this:

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

我面临的问题是,当我使用媒体元素播放录制的音频。该流被锁定到媒体元素。我不能覆盖该文件,甚至再次发挥它作为的SetSource()方法抛出一个异常。

有没有办法迫使媒体元素释放流?

Is there a way to force the media element to release the stream?

推荐答案

根据@Sheridan回答这个它是我想出了工作。

Based on @Sheridan answer this it what I came up with that works.

每当的MediaElement 使用停止停止()功能设置来源属性为是这样的:

Whenever MediaElement is stopped using Stop() function set the Source Property to null like this:

ResetMediaElement()
{
    mediaElement.Stop();
    mediaElement.Source = null;
}

这将关闭连接到媒体元素的流,从而使相关的资源可以在其他地方使用。

This will close the stream attached to the media element, so that the related resource can be used somewhere else.

这篇关于强制的MediaElement在播放后释放流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆