Playlist Playlist Playlist Playlist Playlist Class

Definition

Provides access to a media playlist.

public : sealed class Playlist
struct winrt::Windows::Media::Playlists::Playlist
public sealed class Playlist
Public NotInheritable Class Playlist
var playlist = new playlist();
Attributes

Windows 10 requirements

Device family
Windows Desktop Extension SDK (introduced v10.0.10240.0)
API contract
Windows.Media.Playlists.PlaylistsContract (introduced v1)

Examples

This example is an excerpt from the Playlist sample. See the sample for the complete solution.

// App namespace.
var PlaylistSample = {};
// Create and save a playlist from a set of audio files.
function scenario1Create() {
    var picker = new Windows.Storage.Pickers.FileOpenPicker();
    picker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.musicLibrary;
    picker.fileTypeFilter.replaceAll(["*"]);

    picker.pickMultipleFilesAsync().then(function (items) {
        PlaylistSample.list = new Windows.Media.Playlists.Playlist();

        items.forEach(function (/*@override*/item) { 
            PlaylistSample.list.files.append(item);
        });

        sdkSample.displayStatus("Playlist sample.wpl created. Choose save location.");
    }, function (error) {
        sdkSample.displayError("Error in picking files.");
    });
}

// Save created playlist.
function scenario1Save() {
    var folderpicker = new Windows.Storage.Pickers.FolderPicker();
    folderpicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.musicLibrary;
    folderpicker.fileTypeFilter.replaceAll(["*"]);

    folderpicker.pickSingleFolderAsync().then(function (folder) {
        PlaylistSample.list.saveAsAsync(folder, "sample", Windows.Storage.NameCollisionOption.replaceExisting,
                                        Windows.Media.Playlists.PlaylistFormat.windowsMedia).then(function (file) {
            sdkSample.displayStatus("Playlist sample.wpl saved to the " + folder.name + " folder.");
        });

    }, function (error) {
        sdkSample.displayError("Error in picking folder");
    });
}

// Pick playlist and display its contents.
function scenario2Display() {
    var picker = new Windows.Storage.Pickers.FileOpenPicker();
    picker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.musicLibrary;
    picker.fileTypeFilter.replaceAll([".wpl", ".zpl", ".m3u"]);

    picker.pickSingleFileAsync().then(function (/*@override*/item) {
        Windows.Media.Playlists.Playlist.loadAsync(item).then(function (playlist) {
            // Print the name of the playlist.
            var output = "<p>Playlist content</p>";
            var outputdiv = id("scenario2Output");
            outputdiv.innerHTML = "";
            var promises = {};
            var promiseIndex = 0;
            var musicProperties;

            // Request music properties for each file in the playlist.
            playlist.files.forEach(function (file) {
                promises[promiseIndex] = file.properties.getMusicPropertiesAsync();
                promiseIndex++;
            });

            // Print the music properties for each file. Due to the asynchronous
            // nature of the call to retrieve music properties, the data may appear
            // in an order different than the one specified in the original playlist.
            // To guarantee the ordering we use Promise.join with an associative array
            // passed as a parameter, containing an index for each individual promise.
            WinJS.Promise.join(promises).then(function (results) {
                for (var resultIndex = 0; resultIndex < promiseIndex; resultIndex++) {
                    musicProperties = results[resultIndex];
                    output = output + "<p>Title: " + musicProperties.title + "<br/>";
                    output = output + "Album: " + musicProperties.album + "<br/>";
                    output = output + "Artist: " + musicProperties.artist + "</p>";
                    outputdiv.innerHTML = output;
                }
            });
        });

    }, function (error) {
        sdkSample.displayError("Error in picking file.");
    });
}

Remarks

This API is used to save and load playlist files to and from disk. For information about playing lists of media items, see Media items, playlists, and tracks.

Constructors

Playlist() Playlist() Playlist() Playlist() Playlist()

Creates a new instance of a Playlist object.

Properties

Files Files Files Files Files

The set of media files that make up the playlist.

Methods

LoadAsync(IStorageFile) LoadAsync(IStorageFile) LoadAsync(IStorageFile) LoadAsync(IStorageFile) LoadAsync(IStorageFile)

Asynchronously loads files into a playlist.

SaveAsAsync(IStorageFolder, String, NameCollisionOption) SaveAsAsync(IStorageFolder, String, NameCollisionOption) SaveAsAsync(IStorageFolder, String, NameCollisionOption) SaveAsAsync(IStorageFolder, String, NameCollisionOption) SaveAsAsync(IStorageFolder, String, NameCollisionOption)

Asynchronously saves the playlist to a specified file and folder.

SaveAsAsync(IStorageFolder, String, NameCollisionOption, PlaylistFormat) SaveAsAsync(IStorageFolder, String, NameCollisionOption, PlaylistFormat) SaveAsAsync(IStorageFolder, String, NameCollisionOption, PlaylistFormat) SaveAsAsync(IStorageFolder, String, NameCollisionOption, PlaylistFormat) SaveAsAsync(IStorageFolder, String, NameCollisionOption, PlaylistFormat)

Asynchronously saves the playlist to a specified file and folder, in a specified format.

SaveAsync() SaveAsync() SaveAsync() SaveAsync() SaveAsync()

Asynchronously saves the playlist.

See also