用于在Zune中添加播放列表的API

Kri*_*mar 5 api zune playlist windows-phone-7 windows-phone-8

原始问题(对于Windows Phone 7):我正在使用Windows Phone 7,并希望将下载的播客添加到播放列表中,以便我可以一次性收听它们.不幸的是,UI不允许这样做.我想知道是否有任何API可以做到这一点.

修改后的问题(对于Windows Phone 8):我需要为Windows Phone 8添加"播放列表"api

如有资格获得赏金,请在此处提供和API参考.除了工作API之外,参考链接或样本将不被接受为正确答案.

("不可用/不支持"也不接受作为答案.请不要费心写这些答案)

Jus*_*gel 13

正如我在Twitter上提到的,在Windows Phone 8中,您可以使用MediaLibraryExtensions在设备的音乐库中添加或删除歌曲.这一新功能是在MSDN提到这里.但是,我找不到API的任何文档,所以这里是新的Microsoft.Xna.Framework.MediaLibraryExtensions.dll的API打印输出:

//Microsoft.Xna.Framework.MediaLibraryExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553

namespace Microsoft.Xna.Framework.Media.PhoneExtensions {
    public static class MediaLibraryExtensions {
        public static void Delete(MediaLibrary library, Song song);
        public static String GetPath(Picture picture);
        public static String GetPathFromToken(MediaLibrary library, String token);
        public static Stream GetPreviewImage(Picture picture);
        public static Song SaveSong(MediaLibrary library, Uri filename, SongMetadata songMetadata, SaveSongOperation operation);
    }

    public enum SaveSongOperation {
        CopyToLibrary, 
        MoveToLibrary
    }

    public sealed class SongMetadata {
        public SongMetadata();

        public Uri AlbumArtistBackgroundUri { get; set; }
        public String AlbumArtistName { get; set; }
        public Uri AlbumArtUri { get; set; }
        public String AlbumName { get; set; }
        public DateTime AlbumReleaseDate { get; set; }
        public Uri ArtistBackgroundUri { get; set; }
        public String ArtistName { get; set; }
        public TimeSpan Duration { get; set; }
        public String GenreName { get; set; }
        public String Name { get; set; }
        public Int32 TrackNumber { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

您可以通过使用本地URI调用SaveSong并通过包含自定义SongMetadata来覆盖ID3元数据来使用此新API.此API仅允许您存储新歌曲,但我猜您可以将您的播客分组为一位狡猾的艺术家.关于此API的快速说明是确保添加新的DLL引用MediaLibraryExtensions DLL.您还可以将SongMetadata保持为null并让WP8 OS推断出ID3元数据.

这是一个简单的代码片段:

private async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    var sourceFile = await Package.Current.InstalledLocation.GetFileAsync("ChargeOfTheLightBridge.mp3");
    CopyFileIntoIsoStore(sourceFile);

    var library = new MediaLibrary();
    library.SaveSong(new Uri(sourceFile.Name, UriKind.RelativeOrAbsolute),
                        new SongMetadata()
                        {
                            ArtistName = "My Custom Artist",
                            AlbumArtistName = "My Custom Artist",
                            Name = "My Custom Track Name",
                            AlbumName = "clubbing baby seals in the face",
                            Duration = TimeSpan.FromSeconds(29),
                            TrackNumber = 1,
                            AlbumReleaseDate = DateTime.Now,
                            GenreName = "Podcasts"
                        },
                        SaveSongOperation.CopyToLibrary);
}

private async void CopyFileIntoIsoStore(StorageFile sourceFile)
{
    using (var s = await sourceFile.OpenReadAsync())
    using (var dr = new DataReader(s))
    using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
    using (var targetFile = isoStore.CreateFile(sourceFile.Name))
    {
        var data = new byte[s.Size];
        await dr.LoadAsync((uint) s.Size);
        dr.ReadBytes(data);
        targetFile.Write(data, 0, data.Length);
    }
}
Run Code Online (Sandbox Code Playgroud)

请注意,我们必须在IsoStore中保存文件才能使用此API.另请注意,Uri格式不正确或在标准的IsoStore Uri中.这只是文件名.

当我们运行此代码段时,我们可以看到以下内容:

艺术家列表与自定义艺术家 包含自定义艺术家的专辑列表 自定义艺术家的专辑视图 播放自定义歌曲


Den*_*sky 1

没有访问 Zune API 的默认方法。您可以通过未记录的方式(本机层)来执行此操作,但这最终将使您的应用程序被市场拒绝。