Playlist Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides access to a media playlist.
public ref class Playlist sealed
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Media.Playlists.PlaylistsContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Media.Playlists.PlaylistsContract, 65536)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class Playlist final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Media.Playlists.PlaylistsContract, 65536)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Media.Playlists.PlaylistsContract")]
class Playlist final
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Media.Playlists.PlaylistsContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Media.Playlists.PlaylistsContract), 65536)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class Playlist
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Media.Playlists.PlaylistsContract), 65536)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Media.Playlists.PlaylistsContract")]
public sealed class Playlist
function Playlist()
Public NotInheritable Class Playlist
- Inheritance
- Attributes
Windows requirements
Device family |
Windows Desktop Extension SDK (introduced in 10.0.10240.0)
|
API contract |
Windows.Media.Playlists.PlaylistsContract (introduced in v1.0)
|
Examples
This example is an excerpt from the Playlist sample. See the sample for the complete solution.
// Create and save a playlist from a set of audio files.
async private void PickAudioButton_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker picker = MainPage.CreateFilePicker(MainPage.audioExtensions);
IReadOnlyList<StorageFile> files = await picker.PickMultipleFilesAsync();
if (files.Count > 0)
{
Playlist playlist = new Playlist();
foreach (StorageFile file in files)
{
playlist.Files.Add(file);
}
StorageFolder folder = KnownFolders.MusicLibrary;
string name = "Sample";
NameCollisionOption collisionOption = NameCollisionOption.ReplaceExisting;
PlaylistFormat format = PlaylistFormat.WindowsMedia;
try
{
StorageFile savedFile = await playlist.SaveAsAsync(folder, name, collisionOption, format);
this.rootPage.NotifyUser(savedFile.Name + " was created and saved with " + files.Count + " files.", NotifyType.StatusMessage);
}
catch (Exception error)
{
rootPage.NotifyUser(error.Message, NotifyType.ErrorMessage);
}
}
else
{
rootPage.NotifyUser("No files picked.", NotifyType.ErrorMessage);
}
}
// Pick playlist and display its contents.
async private void PickPlaylistButton_Click(object sender, RoutedEventArgs e)
{
Playlist playlist = await PickPlaylistAsync();
if (playlist != null)
{
string result = "Songs in playlist: " + playlist.Files.Count.ToString() + "\n";
foreach (StorageFile file in playlist.Files)
{
MusicProperties properties = await file.Properties.GetMusicPropertiesAsync();
result += "\n";
result += "File: " + file.Path + "\n";
result += "Title: " + properties.Title + "\n";
result += "Album: " + properties.Album + "\n";
result += "Artist: " + properties.Artist + "\n";
}
this.OutputStatus.Text = result;
}
}
private async Task<Playlist> PickPlaylistAsync()
{
FileOpenPicker picker = CreateFilePicker(MainPage.playlistExtensions);
StorageFile file = await picker.PickSingleFileAsync();
if (file == null)
{
NotifyUser("No playlist picked.", NotifyType.ErrorMessage);
return null;
}
try
{
return await Playlist.LoadAsync(file);
}
catch (Exception ex)
{
NotifyUser(ex.Message, NotifyType.ErrorMessage);
return null;
}
}
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() |
Creates a new instance of a Playlist object. |
Properties
Files |
The set of media files that make up the playlist. |
Methods
LoadAsync(IStorageFile) |
Asynchronously loads files into a playlist. |
SaveAsAsync(IStorageFolder, String, NameCollisionOption, PlaylistFormat) |
Asynchronously saves the playlist to a specified file and folder, in a specified format. |
SaveAsAsync(IStorageFolder, String, NameCollisionOption) |
Asynchronously saves the playlist to a specified file and folder. |
SaveAsync() |
Asynchronously saves the playlist. |