Skip to content

Commit c829add

Browse files
committed
Added docs for IPlayableItem, fixes JohnnyCrazy#454
1 parent ca436c3 commit c829add

6 files changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
id: iplayableitem
3+
title: IPlayableItem
4+
---
5+
6+
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`.
7+
8+
```csharp
9+
var spotify = new SpotifyClient("YourAccessToken");
10+
11+
var playlist = await spotify.Playlists.Get("37i9dQZEVXbMDoHDwVN2tF");
12+
foreach (PlaylistTrack<IPlayableItem> item in playlist.Tracks.Items)
13+
{
14+
// When was it added
15+
Console.WriteLine(item.AddedAt);
16+
// The only propety on item is item.Type, it's a IPlayableItem
17+
Console.WriteLine(item.Track.Type);
18+
}
19+
```
20+
21+
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:
22+
23+
```csharp
24+
foreach (PlaylistTrack<IPlayableItem> item in playlist.Tracks.Items)
25+
{
26+
if (item.Track is FullTrack track)
27+
{
28+
// All FullTrack properties are available
29+
Console.WriteLine(track.Name);
30+
}
31+
if (item.Track is FullEpisode episode)
32+
{
33+
// All FullTrack properties are available
34+
Console.WriteLine(episode.Name);
35+
}
36+
}
37+
```
38+
39+
To this day, `IPlayableItem` can only be `FullTrack` or `FullEpisode`.

‎SpotifyAPI.Docs/sidebars.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = {
1313
'proxy',
1414
'pagination',
1515
'retry_handling',
16+
'iplayableitem',
1617
'unit_testing'
1718
]
1819
},

‎SpotifyAPI.Web/Models/Response/CurrentlyPlaying.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ public class CurrentlyPlaying
99
public string CurrentlyPlayingType { get; set; } = default!;
1010
public bool IsPlaying { get; set; }
1111

12+
/// <summary>
13+
/// Can be a FullTrack or FullEpisode
14+
/// </summary>
15+
/// <value></value>
1216
[JsonConverter(typeof(PlayableItemConverter))]
1317
public IPlayableItem Item { get; set; } = default!;
1418
public int? ProgressMs { get; set; }

‎SpotifyAPI.Web/Models/Response/CurrentlyPlayingContext.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ public class CurrentlyPlayingContext
1212
public int ProgressMs { get; set; }
1313
public bool IsPlaying { get; set; }
1414

15+
/// <summary>
16+
/// Can be a FullTrack or FullEpisode
17+
/// </summary>
18+
/// <value></value>
1519
[JsonConverter(typeof(PlayableItemConverter))]
1620
public IPlayableItem Item { get; set; } = default!;
1721

‎SpotifyAPI.Web/Models/Response/FullPlaylist.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public class FullPlaylist
1212
public PublicUser Owner { get; set; } = default!;
1313
public bool Public { get; set; }
1414
public string SnapshotId { get; set; } = default!;
15+
16+
/// <summary>
17+
/// A list of PlaylistTracks, which items can be a FullTrack or FullEpisode
18+
/// </summary>
19+
/// <value></value>
1520
public Paging<PlaylistTrack<IPlayableItem>> Tracks { get; set; } = default!;
1621
public string Type { get; set; } = default!;
1722
public string Uri { get; set; } = default!;

‎SpotifyAPI.Web/Models/Response/SimplePlaylist.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public class SimplePlaylist
1616
public PublicUser Owner { get; set; } = default!;
1717
public bool? Public { get; set; }
1818
public string SnapshotId { get; set; } = default!;
19+
20+
/// <summary>
21+
/// A list of PlaylistTracks, which items can be a FullTrack or FullEpisode
22+
/// </summary>
23+
/// <value></value>
1924
public Paging<PlaylistTrack<IPlayableItem>> Tracks { get; set; } = default!;
2025
public string Type { get; set; } = default!;
2126
public string Uri { get; set; } = default!;

0 commit comments

Comments
 (0)