我可以在AudioPlayer类中添加数据库查询吗? WP8

时间:2014-03-26 11:08:32

标签: windows-phone-8

我想用我在数据库表中保存的曲目填充我的后台播放器播放列表。 我怎么能在我的Windows Phone 8应用程序中这样做?

1 个答案:

答案 0 :(得分:0)

BackgroundAudioPlayer只能播放来自独立存储或远程URI的文件。您需要做的就是将音轨列表作为播放器的播放列表。

这些只是根据您的需要修改的示例。

//使用IsolatedStorageFileStream文件的Name属性获取uri轨道。  reference

 private static string GetAbsolutePath(string filename)
    {
        IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();

        string absoulutePath = null;

        if (isoStore.FileExists(filename))
        {
            IsolatedStorageFileStream output = new IsolatedStorageFileStream(filename, FileMode.Open, isoStore);
            absoulutePath = output.Name;

            output.Close();
            output = null;
        }

        return absoulutePath;
    }

    //now instantiate list of audio track with the uri to track
    List<AudioTrack>  = new List<AudioTrack>
    {
        new AudioTrack(new Uri("URI TO FILE IN ISOLATED STORAGE", UriKind.Relative), 
                "title",
                "artist",
                "album",
                "Uri To albumArt or null"),

        new AudioTrack(new Uri("URI TO FILE IN ISOLATED STORAGE", UriKind.Relative), 
                "title",
                "artist",
                "album",
                "Uri To albumArt or null")
    };

进一步阅读:http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202978(v=vs.105).aspx