Spotify.NET/assets/js/fbd836ef.3b77dc9b.js

1 line
6.7 KiB
JavaScript
Raw Normal View History

(window.webpackJsonp=window.webpackJsonp||[]).push([[51],{121: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,"toc",(function(){return s})),n.d(t,"default",(function(){return p}));var a=n(3),r=n(7),i=(n(0),n(124)),l={id:"iplayableitem",title:"IPlayableItem"},o={unversionedId:"iplayableitem",id:"iplayableitem",isDocsHomePage:!1,title:"IPlayableItem",description:"When working with playlists or the current playing context, you will encounter the IPlayableItem type, 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",slug:"/iplayableitem",permalink:"/SpotifyAPI-NET/docs/iplayableitem",editUrl:"https://github.com/JohnnyCrazy/SpotifyAPI-NET/edit/master/SpotifyAPI.Docs/docs/iplayableitem.md",version:"current",lastUpdatedBy:"dependabot[bot]",lastUpdatedAt:1622836226,formattedLastUpdatedAt:"6/4/2021",sidebar:"docs",previous:{title:"Retry Handling",permalink:"/SpotifyAPI-NET/docs/retry_handling"},next:{title:"Unit Testing",permalink:"/SpotifyAPI-NET/docs/unit_testing"}},s=[{value:"Fields",id:"fields",children:[]}],c={toc: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 the ",Object(i.b)("inlineCode",{parentName:"p"},"IPlayableItem")," type, 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",{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",{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 unknown playlist element type"),". For example, the following call fails:"),Object(i.b)("pre",null,Object(i.b)("code",{parentName:"pre",className:"language-csharp"},'var playlistGetItemsRequest = new PlaylistGetItemsRequest();\npl