Playlist 类

定义

提供对媒体播放列表的访问。

public ref class Playlist sealed
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Media.Playlists.PlaylistsContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Media.Playlists.PlaylistsContract, 65536)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class Playlist final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Media.Playlists.PlaylistsContract, 65536)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Media.Playlists.PlaylistsContract")]
class Playlist final
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Media.Playlists.PlaylistsContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Media.Playlists.PlaylistsContract), 65536)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class Playlist
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Media.Playlists.PlaylistsContract), 65536)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Media.Playlists.PlaylistsContract")]
public sealed class Playlist
function Playlist()
Public NotInheritable Class Playlist
继承
Object Platform::Object IInspectable Playlist
属性

Windows 要求

设备系列
Windows Desktop Extension SDK (在 10.0.10240.0 中引入)
API contract
Windows.Media.Playlists.PlaylistsContract (在 v1.0 中引入)

示例

此示例是 播放列表示例的摘录。 有关完整解决方案,请参阅示例。

// Create and save a playlist from a set of audio files.
async private void PickAudioButton_Click(object sender, RoutedEventArgs e)
{
    FileOpenPicker picker = MainPage.CreateFilePicker(MainPage.audioExtensions);
    IReadOnlyList<StorageFile> files = await picker.PickMultipleFilesAsync();

    if (files.Count > 0)
    {
        Playlist playlist = new Playlist();

        foreach (StorageFile file in files)
        {
            playlist.Files.Add(file);
        }

        StorageFolder folder = KnownFolders.MusicLibrary;
        string name = "Sample";
        NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting;
        PlaylistFormat format = PlaylistFormat.WindowsMedia;

        try
        {
            StorageFile savedFile = await playlist.SaveAsAsync(folder, name, collisionOption, format);
            this.rootPage.NotifyUser(savedFile.Name + " was created and saved with " + files.Count + " files.", NotifyType.StatusMessage);
        }
        catch (Exception error)
        {
            rootPage.NotifyUser(error.Message, NotifyType.ErrorMessage);
        }
    }
    else
    {
        rootPage.NotifyUser("No files picked.", NotifyType.ErrorMessage);
    }
}

// Pick playlist and display its contents.
async private void PickPlaylistButton_Click(object sender, RoutedEventArgs e)
{
    Playlist playlist = await PickPlaylistAsync();

    if (playlist != null)
    {
        string result = "Songs in playlist: " + playlist.Files.Count.ToString() + "\n";

        foreach (StorageFile file in playlist.Files)
        {
            MusicProperties properties = await file.Properties.GetMusicPropertiesAsync();
            result += "\n";
            result += "File: " + file.Path + "\n";
            result += "Title: " + properties.Title + "\n";
            result += "Album: " + properties.Album + "\n";
            result += "Artist: " + properties.Artist + "\n";
        }

        this.OutputStatus.Text = result;
    }
}

private async Task<Playlist> PickPlaylistAsync()
{
    FileOpenPicker picker = CreateFilePicker(MainPage.playlistExtensions);
    StorageFile file = await picker.PickSingleFileAsync(); 

    if (file == null)
    {
        NotifyUser("No playlist picked.", NotifyType.ErrorMessage);
        return null;
    }

    try
    {
        return await Playlist.LoadAsync(file);
    }
    catch (Exception ex)
    {
        NotifyUser(ex.Message, NotifyType.ErrorMessage);
        return null;
    }
}

注解

此 API 用于在磁盘和磁盘中保存和加载播放列表文件。 有关播放媒体项目列表的信息,请参阅 媒体项目、播放列表和曲目

构造函数

Playlist()

创建 Playlist 对象的新实例。

属性

Files

构成播放列表的媒体文件集。

方法

LoadAsync(IStorageFile)

以异步方式将文件加载到播放列表中。

SaveAsAsync(IStorageFolder, String, NameCollisionOption)

异步将播放列表保存到指定的文件和文件夹。

SaveAsAsync(IStorageFolder, String, NameCollisionOption, PlaylistFormat)

以指定的格式异步将播放列表保存到指定的文件和文件夹。

SaveAsync()

异步保存播放列表。

适用于

另请参阅