Playing media file from Isolated Storage in windows phone?

戏子无情 提交于 2019-12-24 03:35:38

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/9357083/playing-media-file-from-isolated-storage-in-windows-phone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!