Playlist, classe
Réduire la table des matières
Développer la table des matières

Playlist Class

Permet d'accéder à une sélection multimédia.

Syntaxe


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

Attributs

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

Membres

PlaylistClasse possède ces types de membres :

Constructeurs

PlaylistClasse possède ces constructeurs.

ConstructeurDescription
Playlist Creates a new instance of a Playlist object.

 

Méthodes

The Playlist Classe a les méthodes suivantes. Avec C#, Visual Basic et C++, elle hérite également des méthodes de Object Classe.

MéthodeDescription
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.

 

Propriétés

Le PlaylistClasse a les propriétés suivantes.

PropriétéType d'accèsDescription

Files

En lecture seuleThe set of media files that make up the playlist.

 

Exemples

Cet exemple est issu de l'extrait de l'exemple de sélection. Pour obtenir la solution complète, consultez l'exemple.


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

Conditions requises

Client minimal pris en charge

Windows 8 [Applications Windows Store, applications de bureau]

Serveur minimal pris en charge

Windows Server 2012 [Applications Windows Store, applications de bureau]

Espace de noms

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

Métadonnées

Windows.winmd

Voir aussi

Exemple de sélection

 

 

Afficher:
© 2016 Microsoft