Playlist Klasse

Definition

Bietet Zugriff auf eine Medienwiedergabeliste.

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
Vererbung
Object Platform::Object IInspectable Playlist
Attribute

Windows-Anforderungen

Gerätefamilie
Windows Desktop Extension SDK (eingeführt in 10.0.10240.0)
API contract
Windows.Media.Playlists.PlaylistsContract (eingeführt in v1.0)

Beispiele

Dieses Beispiel ist ein Auszug aus dem Wiedergabelistenbeispiel. Sehen Sie sich das Beispiel für die vollständige Lösung an.

// 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;
    }
}

Hinweise

Diese API wird zum Speichern und Laden von Wiedergabelistendateien auf und von datenträgern verwendet. Informationen zum Wiedergeben von Listen von Medienelementen finden Sie unter Medienelemente, Wiedergabelisten und Titel.

Konstruktoren

Playlist()

Erstellt eine neue instance eines Playlist-Objekts.

Eigenschaften

Files

Der Satz von Mediendateien, aus denen die Wiedergabeliste besteht.

Methoden

LoadAsync(IStorageFile)

Lädt Dateien asynchron in eine Wiedergabeliste.

SaveAsAsync(IStorageFolder, String, NameCollisionOption)

Speichert die Wiedergabeliste asynchron in einer angegebenen Datei und einem angegebenen Ordner.

SaveAsAsync(IStorageFolder, String, NameCollisionOption, PlaylistFormat)

Speichert die Wiedergabeliste asynchron in einer angegebenen Datei und einem angegebenen Ordner in einem angegebenen Format.

SaveAsync()

Speichert die Wiedergabeliste asynchron.

Gilt für:

Weitere Informationen