mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-23 22:56:25 +00:00
1 line
6.7 KiB
JavaScript
1 line
6.7 KiB
JavaScript
|
(window.webpackJsonp=window.webpackJsonp||[]).push([[51],{183:function(e,t,n){"use strict";n.r(t),n.d(t,"frontMatter",(function(){return l})),n.d(t,"metadata",(function(){return o})),n.d(t,"rightToc",(function(){return s})),n.d(t,"default",(function(){return p}));var a=n(2),r=n(9),i=(n(0),n(186)),l={id:"iplayableitem",title:"IPlayableItem"},o={id:"iplayableitem",title:"IPlayableItem",description:"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.",source:"@site/docs/iplayableitem.md",permalink:"/SpotifyAPI-NET/docs/next/iplayableitem",editUrl:"https://github.com/JohnnyCrazy/SpotifyAPI-NET/edit/master/SpotifyAPI.Docs/docs/iplayableitem.md",version:"next",lastUpdatedBy:"Jonas Dellinger",lastUpdatedAt:1593631555,sidebar:"docs",previous:{title:"Retry Handling",permalink:"/SpotifyAPI-NET/docs/next/retry_handling"},next:{title:"Unit Testing",permalink:"/SpotifyAPI-NET/docs/next/unit_testing"}},s=[{value:"Fields",id:"fields",children:[]}],c={rightToc:s};function p(e){var t=e.components,n=Object(r.a)(e,["components"]);return Object(i.b)("wrapper",Object(a.a)({},c,n,{components:t,mdxType:"MDXLayout"}),Object(i.b)("p",null,"When working with playlists or the current playing context, you will encounter a type ",Object(i.b)("inlineCode",{parentName:"p"},"IPlayableItem"),", which only contains a ",Object(i.b)("inlineCode",{parentName:"p"},"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 ",Object(i.b)("inlineCode",{parentName:"p"},"IPlayableItem"),"."),Object(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"},{className:"language-csharp"}),'var spotify = new SpotifyClient("YourAccessToken");\n\nvar playlist = await spotify.Playlists.Get("37i9dQZEVXbMDoHDwVN2tF");\nforeach (PlaylistTrack<IPlayableItem> item in playlist.Tracks.Items)\n{\n // When was it added\n Console.WriteLine(item.AddedAt);\n // The only propety on item is item.Type, it\'s a IPlayableItem\n Console.WriteLine(item.Track.Type);\n}\n')),Object(i.b)("p",null,"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 ",Object(i.b)("inlineCode",{parentName:"p"},"IPlayableItem")," to the respective type:"),Object(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"},{className:"language-csharp"}),"foreach (PlaylistTrack<IPlayableItem> item in playlist.Tracks.Items)\n{\n if (item.Track is FullTrack track)\n {\n // All FullTrack properties are available\n Console.WriteLine(track.Name);\n }\n if (item.Track is FullEpisode episode)\n {\n // All FullTrack properties are available\n Console.WriteLine(episode.Name);\n }\n}\n")),Object(i.b)("p",null,"To this day, ",Object(i.b)("inlineCode",{parentName:"p"},"IPlayableItem")," can only be ",Object(i.b)("inlineCode",{parentName:"p"},"FullTrack")," or ",Object(i.b)("inlineCode",{parentName:"p"},"FullEpisode"),"."),Object(i.b)("h2",{id:"fields"},"Fields"),Object(i.b)("p",null,"When requesting just a subset of fields using the ",Object(i.b)("inlineCode",{parentName:"p"},"fields")," query parameter, the call might fail with an exception similar to ",Object(i.b)("inlineCode",{parentName:"p"},"Received unkown playlist element type"),". For example, the following call fails:"),Object(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"},{className:"language-csharp"}),'var playlistGetItemsRequest = new PlaylistGetItemsRequest();\nplaylistGetItemsRequest.Fields.Add("items(tr
|