BackgroundMediaPlayer set Uri source of Media library item

独自空忆成欢 提交于 2019-12-11 03:27:57

问题


WP 8.1 have BackgroundMediaPlayer to play background audio.

http://www.jayway.com/2014/04/24/windows-phone-8-1-for-developers-the-background-media-player/

In this tutorial author setting up ms-appx source to play song:

BackgroundMediaPlayer.Current.SetUriSource(new Uri("ms-appx:///Assets/Media/Ring01.wma"));

Successful. But, how can I SetUriSource up with Audio from Music Library? Using only SetUriSource because:

The new background player got three simple methods for playing songs. SetFileSource, SetStreamSource and SetUriSource. Only one of these can be called from the foreground application, namely the SetUriSource method. The others needs to be used from your task instead. The reason for this is that the background player don´t have access to the memory where SetFIleSource or SetStreamSource is located unless it is set in the task.

Where I can read advanced about WP8.1? Thank you for advance.


回答1:


You can set your Uri with a file from MusicLibrary by using file's full system path. For example like this:

StorageFile file = (await KnownFolders.MusicLibrary.GetFilesAsync()).FirstOrDefault();
BackgroundMediaPlayer.Current.SetUriSource(new Uri(file.Path, UriKind.RelativeOrAbsolute));



回答2:


You cannot use SetUriSource to access files from the library or removable storage, at least not from the background task. You need to use SetFileSource or SetStreamSource instead. This is not documented anywhere, unfortunately.



来源:https://stackoverflow.com/questions/24509852/backgroundmediaplayer-set-uri-source-of-media-library-item

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