Playlist Classe
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Fournit l’accès à une playlist multimédia.
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
- Héritage
- Attributs
Configuration requise pour Windows
Famille d’appareils |
Windows Desktop Extension SDK (introduit dans 10.0.10240.0)
|
API contract |
Windows.Media.Playlists.PlaylistsContract (introduit dans v1.0)
|
Exemples
Cet exemple est un extrait de l’exemple Playlist. Consultez l’exemple pour obtenir la solution complète.
// 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;
}
}
Remarques
Cette API est utilisée pour enregistrer et charger des fichiers de playlist vers et à partir du disque. Pour plus d’informations sur la lecture des listes d’éléments multimédias, consultez Éléments multimédias, playlists et pistes.
Constructeurs
Playlist() |
Crée une instance d’un objet Playlist. |
Propriétés
Files |
Ensemble de fichiers multimédias qui composent la playlist. |
Méthodes
LoadAsync(IStorageFile) |
Charge de manière asynchrone des fichiers dans une playlist. |
SaveAsAsync(IStorageFolder, String, NameCollisionOption) |
Enregistre de manière asynchrone la playlist dans un fichier et un dossier spécifiés. |
SaveAsAsync(IStorageFolder, String, NameCollisionOption, PlaylistFormat) |
Enregistre de manière asynchrone la playlist dans un fichier et un dossier spécifiés, dans un format spécifié. |
SaveAsync() |
Enregistre de manière asynchrone la playlist. |