Playlist Playlist Playlist Class

Definition

Provides access to a media playlist.

public sealed class Playlist : IPlaylistpublic sealed class Playlist : IPlaylistPublic NotInheritable Class Playlist Implements IPlaylist
Attributes
Windows 10 requirements
Device family
Windows Desktop Extension SDK (introduced v10.0.10240.0)
API contract
Windows.Media.Playlists.PlaylistsContract (introduced v1)

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.

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.");
    });
}

Constructors

Playlist() Playlist() Playlist()

Creates a new instance of a Playlist object.

public Playlist()public Playlist()Public Sub New()
Attributes

Properties

Files Files Files

The set of media files that make up the playlist.

public IVector<StorageFile> Files { get; }public IVector<StorageFile> Files { get; }Public ReadOnly Property Files As IVector<StorageFile>
Value

The list of media files that make up the playlist.

Attributes
See Also

Methods

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

Asynchronously loads files into a playlist.

public static IAsyncOperation<Playlist> LoadAsync(IStorageFile file)public static IAsyncOperation<Playlist> LoadAsync(IStorageFile file)Public Static Function LoadAsync(file As IStorageFile) As IAsyncOperation( Of Playlist )
Parameters
file
IStorageFile IStorageFile IStorageFile

Represents the files to load.

Returns

Represents the asynchronous operation for loading the playlist. The GetResults method of this IAsyncOperation object returns the playlist.

Attributes
See Also

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

Asynchronously saves the playlist to a specified file and folder.

public IAsyncOperation<StorageFile> SaveAsAsync(IStorageFolder saveLocation, String desiredName, NameCollisionOption option)public IAsyncOperation<StorageFile> SaveAsAsync(IStorageFolder saveLocation, String desiredName, NameCollisionOption option)Public Function SaveAsAsync(saveLocation As IStorageFolder, desiredName As String, option As NameCollisionOption) As IAsyncOperation( Of StorageFile )
Parameters
saveLocation
IStorageFolder IStorageFolder IStorageFolder

The folder in which to save the playlist.

desiredName
System.String System.String System.String

The name of the playlist to save.

option
NameCollisionOption NameCollisionOption NameCollisionOption

The action to take if the playlist is saved to an existing file. One of the values of the NameCollisionOption enumeration.

Returns

Represents the asynchronous operation to save the playlist to a specified file and folder.

Attributes

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.

public IAsyncOperation<StorageFile> SaveAsAsync(IStorageFolder saveLocation, String desiredName, NameCollisionOption option, PlaylistFormat playlistFormat)public IAsyncOperation<StorageFile> SaveAsAsync(IStorageFolder saveLocation, String desiredName, NameCollisionOption option, PlaylistFormat playlistFormat)Public Function SaveAsAsync(saveLocation As IStorageFolder, desiredName As String, option As NameCollisionOption, playlistFormat As PlaylistFormat) As IAsyncOperation( Of StorageFile )
Parameters
saveLocation
IStorageFolder IStorageFolder IStorageFolder

The folder in which to save the playlist.

desiredName
System.String System.String System.String

The name of the playlist to save.

option
NameCollisionOption NameCollisionOption NameCollisionOption

The action to take if the playlist is saved to an existing file. One of the values of the NameCollisionOption enumeration.

playlistFormat
PlaylistFormat PlaylistFormat PlaylistFormat

The playlist format. One of the values of the PlaylistFormat enumeration.

Returns

Represents the asynchronous operation to save the playlist to a specified file and folder.

Attributes

SaveAsync() SaveAsync() SaveAsync()

Asynchronously saves the playlist.

public IAsyncAction SaveAsync()public IAsyncAction SaveAsync()Public Function SaveAsync() As IAsyncAction
Returns

Represents the asynchronous action to save the playlist.

Attributes

See Also