在 Windows 手机中从独立存储播放媒体文件? [英] Playing media file from Isolated Storage in windows phone?

查看:39
本文介绍了在 Windows 手机中从独立存储播放媒体文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从独立存储中播放音乐文件.我就是这样做的,

I need to play music file from the isolated storage. i did by this way,

MediaElement media = new MediaElement();

using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())

{
    using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile(FileName, FileMode.Open, FileAccess.Read))
    {
         media.SetSource(fileStream);
         media.Play();
    }
}

我无法播放音乐文件.当我创建媒体元素 Xaml 并设置该元素的源时,这工作正常.问题是,我必须动态创建所有控件.

I can't play the music file. When i created media element Xaml and set source that element this works fine. The problem is, i have to create all controls dynamically.

请建议我如何解决这个问题...

Pls suggest me how to resolve this pblm...

谢谢

推荐答案

您需要将此 MediaElement 添加到您的可视化树中.或者换句话说,MediaElement 应该是 PhoneApplicationPage 的一部分.

You need to add this MediaElement to your visual tree. Or in other words the MediaElement should be part of your PhoneApplicationPage.

假设您的页面中有一个 Grid 并将此 MediaElement 添加到该网格中.

Assume you have a Grid inside your page and add this MediaElement to the grid.

grid.Children.Add(media);

然后你可以设置源以及播放()媒体.

And then you can set the Source as well as Play() the media.

这篇关于在 Windows 手机中从独立存储播放媒体文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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