问题
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