Windows 8 Metro 应用程序中的 Mediaelement [英] Mediaelement in Windows 8 Metro App

查看:38
本文介绍了Windows 8 Metro 应用程序中的 Mediaelement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个特定于我的应用程序的场景.我正在为我的 Metro 应用管理 XML 格式的音乐文件播放列表.它保存音乐文件的实际路径是这样的

I have a scenario specific to my app. I am managing music file playlist in XML for my metro app. And its saving music files actual path like this

D:\MyMedia\1.mp3

D:\MyMedia\1.mp3

我的 XAML 页面中有媒体元素,我正在像这样设置它的来源.

I have media element in my XAML page and I am setting its Source like this.

 mediaElement.Source = new Uri(@"D:\MyMedia\1.mp3", UriKind.Absolute);
 mediaElement.Play();

但它不播放媒体并给出这样的错误

but its not playing the media and its giving the error like this

MF_MEDIA_ENGINE_ERR_SRC_NOT_SUPPORTED : HRESULT - 0x80070005

所以有人告诉我如何使用绝对路径在 Metro 应用程序的 MediaElement 中播放一些媒体文件.或者如何获取本地文件流以在 Metro 应用的 mediaElement 中播放此媒体.

So someone tell me how I can play some media file in MediaElement of metro app with absoulte path. Or how I can get stream of my local file to play this media in my mediaElement of Metro app.

推荐答案

要打开本地系统上的文件,可以使用 FileOpenPicker 获取文件和 SetSource 设置媒体源.

To open files on the local system, you can use the FileOpenPicker to get the file and SetSource to set the media source.

var openPicker = new Windows.Storage.Pickers.FileOpenPicker();

openPicker.FileTypeFilter.Add(".mp3");
var file = await openPicker.PickSingleFileAsync();

var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

if (null != file)
{
    mediaElement.SetSource(stream, file.ContentType);
    mediaElement.Play();
}

这篇关于Windows 8 Metro 应用程序中的 Mediaelement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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