2014-07-01 29 views
2

WP 8.1有BackgroundMediaPlayer播放背景音樂。BackgroundMediaPlayer設置媒體庫項目的開放的源

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

在本教程中作者建立MS-APPX源播放的歌曲:

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

成功。 但是,我怎樣才能SetUriSource與音樂庫音頻?僅使用SetUriSource,因爲:

新的背景播放器有三種播放歌曲的簡單方法。 SetFileSource,SetStreamSource和SetUriSource。只有其中的一個可以從前臺應用程序調用,即SetUriSource方法。其他人需要從你的任務中使用。原因是後臺播放器沒有訪問SetFIleSource或SetStreamSource所在的內存,除非它在任務中設置。

我在哪裏可以閱讀有關先進WP8.1? 謝謝你的提前。

回答

1

通過使用文件的完整系統路徑,您可以使用MusicLibrary中的文件設置您的Uri。例如像這樣:

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

不幸的是,它不工作。新的URI(pathSource,UriKind.RelativeOrAbsolute)有這個字符串:{文件:/// C:/數據/用戶/公共/音樂/ CD - 1/Test001.mp3} – sahap

+0

但是,新的URI(「MS-APPX:// /Assets/Media/Ring01.wma「)工作正常。 – sahap

+0

@RegisteredUser正如我測試它工作得很好。你可以試試:'新的Uri(@「C:/ Data/Users/Public/Music/CD-1/Test001.mp3」,UriKind.RelativeOrAbsolute)'?你有沒有加入MusicLibrary功能? – Romasz

4

不能使用SetUriSource從圖書館或可移動存儲訪問文件,至少不是從後臺任務。您需要改用SetFileSource或SetStreamSource。不幸的是,這沒有記錄在任何地方。