从 wp7 中的独立存储流式传输视频
我正在尝试制作一些 wp7 应用程序,它应该从服务器播放视频。 该应用程序的功能之一是下载选定的视频并从独立存储中播放它们。
我正在使用下一个代码进行下载:
WebClient wc = new WebClient();
wc.OpenReadCompleted += (s, a) => { /* saving result stream to isolated storage */}
wc.OpenReadAsync(fileUri);
所以,当我单击播放按钮时,我检查文件是否已下载,如果是,我打开该文件的isolatedStorageFileStream并将其设置为播放器的源,否则我设置为源文件乌里。
问题是,当我尝试将isolatedStorageFileStream 设置为 MedialElement 的源时,出现 MediaFailed 异常。有人可以帮我吗?
代码看起来像下一种方式
private IsolatedStorageFile isf;
private IsolatedStorageFileStream stream;
private void playButton_Click(..)
{
isf = IsolatedStorageFile.GetUserStoreForApplication();
stream = isf.OpenFile(path, FileMode.Open);
MediaPlayer.SetSource(stream);
MediaPlayer.Play();
}
Stream 没有损坏,它的长度是正确的。我真的不知道该怎么办。 提前致谢
I'm trying to make some wp7 app which should play videos from server.
One of the app's features is downloading selected videos and playing them from isolated storage.
I'm using next code for downloading:
WebClient wc = new WebClient();
wc.OpenReadCompleted += (s, a) => { /* saving result stream to isolated storage */}
wc.OpenReadAsync(fileUri);
So, when I click on play button, I check if file was downloaded or not, and if it was I open IsolatedStorageFileStream for this file and set it to player's source, otherwise I set to source file Uri.
Problem is that I get MediaFailed exception when I'm trying to set IsolatedStorageFileStream as MedialElement's source. Can anybody help me with it?
Code looks like in next way
private IsolatedStorageFile isf;
private IsolatedStorageFileStream stream;
private void playButton_Click(..)
{
isf = IsolatedStorageFile.GetUserStoreForApplication();
stream = isf.OpenFile(path, FileMode.Open);
MediaPlayer.SetSource(stream);
MediaPlayer.Play();
}
Stream is not corrupted, its length is correct. I realy don't know what to do with it.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了解决方案,这很奇怪,但有效
问题是我保存名称为 %clipId%.clip 的文件,但是当我将文件名更改为 %clipId%.mp4 (我的剪辑以 mp4 编码)时,它就可以工作了!!!
无法理解为什么会这样。
I've found solution, it's very strange, but works
The problem was that I save files with names %clipId%.clip, but when I changed file names to %clipId%.mp4 (my clips are encoded in mp4) it becomes work!!!
Can't understand why it is so.
媒体播放器查看文件名以检查它是否支持该格式。 “.clip”不是有效的格式。
The media player looks at the filename to check if it supports the format. ".clip" is no valid format.