Playlist class

Applies to Windows only

Provides access to a media playlist.

Syntax


var playlist = new Windows.Media.Playlists.Playlist();

Attributes

[DualApiPartition()]
[Threading(Both)]
[Version(0x06020000)]

Members

The Playlist class has these types of members:

Constructors

The Playlist class has these constructors.

ConstructorDescription
Playlist Creates a new instance of a Playlist object.

 

Methods

The Playlist class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
LoadAsync Asynchronously loads files into a playlist.
SaveAsAsync(IStorageFolder, String, NameCollisionOption) Asynchronously saves the playlist to a specified file and folder.
SaveAsAsync(IStorageFolder, String, NameCollisionOption, PlaylistFormat) Asynchronously saves the playlist to a specified file and folder, in a specified format.
SaveAsync Asynchronously saves the playlist.

 

Properties

The Playlist class has these properties.

PropertyAccess typeDescription

Files

Read-onlyThe set of media files that make up the playlist.

 

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

Requirements

Minimum supported client

Windows 8 [Windows Store apps, desktop apps]

Minimum supported server

Windows Server 2012 [Windows Store apps, desktop apps]

Minimum supported phone

None supported

Namespace

Windows.Media.Playlists
Windows::Media::Playlists [C++]

Metadata

Windows.winmd

See also

Playlist sample

 

 

Show:
© 2014 Microsoft