在 Zune 中添加播放列表的 API [英] API to add playlists in Zune

查看:19
本文介绍了在 Zune 中添加播放列表的 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Original Question (for windows phone 7): I am using windows phone 7 and would like to add downloaded podcasts to a play list so that I can listen to them in a single go. Unfortunately UI does not allow this. I would like to know whether there are any API to do this.

修改后的问题(适用于 windows phone 8):我需要 windows phone 8 的添加到播放列表"api

Modified Question (for windows phone 8): I need "add to playlist" api for windows phone 8

要获得赏金,请在此处提供 API 参考.除了有效的 API 参考链接或示例之外,不接受作为正确答案.

For being entitled for bounty please provide and API reference here. Other than working API reference link or sample will not be accepted as a correct answer.

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

推荐答案

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

As I mentioned on twitter, in Windows Phone 8 you can add or remove songs from the device's music library using MediaLibraryExtensions. The new capability is mentioned on MSDN here. However, I couldn't find any documentation for the APIs, so here's the API printout for the new Microsoft.Xna.Framework.MediaLibraryExtensions.dll:

//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 OS 推断 ID3 元数据.

You can use this new API by invoking SaveSong with a local URI and by potentially overriding the ID3 metadata by including a custom SongMetadata. This API only allows you to store new songs, but I guess you can group your podcasts under a factious artist. Quick note about this API is to make sure to add the new DLL reference MediaLibraryExtensions DLL. You can also can keep SongMetadata as null and have the WP8 OS infer ID3 metadata.

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

Here's a simple code snippet:

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.这只是文件名.

Note that we had to save a file in IsoStore to use this API. Also note that the Uri isn't well-formed or in a standard IsoStore Uri. It's just the file name.

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

When we run this code snippet we can see the following:

这篇关于在 Zune 中添加播放列表的 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆