在 Windows Phone 中播放独立存储中的媒体文件?

发布于 2025-01-07 04:47:38 字数 492 浏览 6 评论 0原文

我需要播放独立存储中的音乐文件。我按照这个方法,

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

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...

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慵挽 2025-01-14 04:47:38

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

假设您的页面中有一个网格,并将此 MediaElement 添加到网格中。

grid.Children.Add(media);

然后您可以设置 Source 以及 Play() 媒体。

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文