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

时间:2010-12-08 09:19:39

标签: api windows-phone-7 windows-phone-8 playlist zune

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

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

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

(“不可用/不支持”也不接受答案。请不要费心写下这些答案)

2 个答案:

答案 0 :(得分:13)

作为mentioned on twitter,在Windows Phone 8中,您可以使用MediaLibraryExtensions在设备的音乐库中添加或删除歌曲。 MSDN here上提到了新功能。但是,我找不到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; }
    }
}

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

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

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

Artist list with custom artist Album list with custom artist Album view for custom artist playing a custom song

答案 1 :(得分:1)

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