mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-23 14:46:26 +00:00
Added docs for IPlayableItem, fixes #454
This commit is contained in:
parent
ca436c3099
commit
c829adde0b
39
SpotifyAPI.Docs/docs/iplayableitem.md
Normal file
39
SpotifyAPI.Docs/docs/iplayableitem.md
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
---
|
||||||
|
id: iplayableitem
|
||||||
|
title: IPlayableItem
|
||||||
|
---
|
||||||
|
|
||||||
|
When working with playlists or the current playing context, you will encounter a type `IPlayableItem`, which only contains a `Type` property. Spotify recently introduced shows/episodes to the API, and thus had to adapt API endpoints which previously just returned track objects. Now, playlists and the current playing context can include two types, tracks and episodes. To reflect this in our models, we introduced `IPlayableItem`.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var spotify = new SpotifyClient("YourAccessToken");
|
||||||
|
|
||||||
|
var playlist = await spotify.Playlists.Get("37i9dQZEVXbMDoHDwVN2tF");
|
||||||
|
foreach (PlaylistTrack<IPlayableItem> item in playlist.Tracks.Items)
|
||||||
|
{
|
||||||
|
// When was it added
|
||||||
|
Console.WriteLine(item.AddedAt);
|
||||||
|
// The only propety on item is item.Type, it's a IPlayableItem
|
||||||
|
Console.WriteLine(item.Track.Type);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Now, this type per se is probably useless to you. You're interested in the name, uri or artist of the episode/track. To get that info, you have to type cast the `IPlayableItem` to the respective type:
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
foreach (PlaylistTrack<IPlayableItem> item in playlist.Tracks.Items)
|
||||||
|
{
|
||||||
|
if (item.Track is FullTrack track)
|
||||||
|
{
|
||||||
|
// All FullTrack properties are available
|
||||||
|
Console.WriteLine(track.Name);
|
||||||
|
}
|
||||||
|
if (item.Track is FullEpisode episode)
|
||||||
|
{
|
||||||
|
// All FullTrack properties are available
|
||||||
|
Console.WriteLine(episode.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To this day, `IPlayableItem` can only be `FullTrack` or `FullEpisode`.
|
@ -13,6 +13,7 @@ module.exports = {
|
|||||||
'proxy',
|
'proxy',
|
||||||
'pagination',
|
'pagination',
|
||||||
'retry_handling',
|
'retry_handling',
|
||||||
|
'iplayableitem',
|
||||||
'unit_testing'
|
'unit_testing'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -9,6 +9,10 @@ namespace SpotifyAPI.Web
|
|||||||
public string CurrentlyPlayingType { get; set; } = default!;
|
public string CurrentlyPlayingType { get; set; } = default!;
|
||||||
public bool IsPlaying { get; set; }
|
public bool IsPlaying { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Can be a FullTrack or FullEpisode
|
||||||
|
/// </summary>
|
||||||
|
/// <value></value>
|
||||||
[JsonConverter(typeof(PlayableItemConverter))]
|
[JsonConverter(typeof(PlayableItemConverter))]
|
||||||
public IPlayableItem Item { get; set; } = default!;
|
public IPlayableItem Item { get; set; } = default!;
|
||||||
public int? ProgressMs { get; set; }
|
public int? ProgressMs { get; set; }
|
||||||
|
@ -12,6 +12,10 @@ namespace SpotifyAPI.Web
|
|||||||
public int ProgressMs { get; set; }
|
public int ProgressMs { get; set; }
|
||||||
public bool IsPlaying { get; set; }
|
public bool IsPlaying { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Can be a FullTrack or FullEpisode
|
||||||
|
/// </summary>
|
||||||
|
/// <value></value>
|
||||||
[JsonConverter(typeof(PlayableItemConverter))]
|
[JsonConverter(typeof(PlayableItemConverter))]
|
||||||
public IPlayableItem Item { get; set; } = default!;
|
public IPlayableItem Item { get; set; } = default!;
|
||||||
|
|
||||||
|
@ -12,6 +12,11 @@ namespace SpotifyAPI.Web
|
|||||||
public PublicUser Owner { get; set; } = default!;
|
public PublicUser Owner { get; set; } = default!;
|
||||||
public bool Public { get; set; }
|
public bool Public { get; set; }
|
||||||
public string SnapshotId { get; set; } = default!;
|
public string SnapshotId { get; set; } = default!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A list of PlaylistTracks, which items can be a FullTrack or FullEpisode
|
||||||
|
/// </summary>
|
||||||
|
/// <value></value>
|
||||||
public Paging<PlaylistTrack<IPlayableItem>> Tracks { get; set; } = default!;
|
public Paging<PlaylistTrack<IPlayableItem>> Tracks { get; set; } = default!;
|
||||||
public string Type { get; set; } = default!;
|
public string Type { get; set; } = default!;
|
||||||
public string Uri { get; set; } = default!;
|
public string Uri { get; set; } = default!;
|
||||||
|
@ -16,6 +16,11 @@ namespace SpotifyAPI.Web
|
|||||||
public PublicUser Owner { get; set; } = default!;
|
public PublicUser Owner { get; set; } = default!;
|
||||||
public bool? Public { get; set; }
|
public bool? Public { get; set; }
|
||||||
public string SnapshotId { get; set; } = default!;
|
public string SnapshotId { get; set; } = default!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A list of PlaylistTracks, which items can be a FullTrack or FullEpisode
|
||||||
|
/// </summary>
|
||||||
|
/// <value></value>
|
||||||
public Paging<PlaylistTrack<IPlayableItem>> Tracks { get; set; } = default!;
|
public Paging<PlaylistTrack<IPlayableItem>> Tracks { get; set; } = default!;
|
||||||
public string Type { get; set; } = default!;
|
public string Type { get; set; } = default!;
|
||||||
public string Uri { get; set; } = default!;
|
public string Uri { get; set; } = default!;
|
||||||
|
Loading…
Reference in New Issue
Block a user