Playlist 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// You can use this class in JavaScript.
- Attributes
| 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
Properties
Files Files Files Files
The set of media files that make up the playlist.
public : IVector<StorageFile> Files { get; }public IList<StorageFile> Files { get; }Public ReadOnly Property Files As IList<StorageFile>// You can use this property in JavaScript.
- Value
- IVector<StorageFile> IList<StorageFile> IList<StorageFile> IList<StorageFile>
The list of media files that make up the playlist.
- See Also
Methods
LoadAsync(IStorageFile) 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 )// You can use this method in JavaScript.
Represents the files to load.
Represents the asynchronous operation for loading the playlist. The GetResults method of this IAsyncOperation object returns the playlist.
- See Also
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.
public : IAsyncOperation<StorageFile> SaveAsAsync(IStorageFolder saveLocation, PlatForm::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 )// You can use this method in JavaScript.
- saveLocation
- IStorageFolder IStorageFolder IStorageFolder IStorageFolder
The folder in which to save the playlist.
- desiredName
- PlatForm::String String String String
The name of the playlist to save.
The action to take if the playlist is saved to an existing file. One of the values of the NameCollisionOption enumeration.
Represents the asynchronous operation to save the playlist to a specified file and folder.
- See Also
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.
public : IAsyncOperation<StorageFile> SaveAsAsync(IStorageFolder saveLocation, PlatForm::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 )// You can use this method in JavaScript.
- saveLocation
- IStorageFolder IStorageFolder IStorageFolder IStorageFolder
The folder in which to save the playlist.
- desiredName
- PlatForm::String String String String
The name of the playlist to save.
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 PlaylistFormat
The playlist format. One of the values of the PlaylistFormat enumeration.
Represents the asynchronous operation to save the playlist to a specified file and folder.
- See Also