|
4 | 4 | using SpotifyAPI.Web.Models; |
5 | 5 | using System; |
6 | 6 | using System.Collections.Generic; |
| 7 | +using System.Dynamic; |
7 | 8 | using System.Linq; |
8 | 9 | using System.Runtime.InteropServices; |
9 | 10 | using System.Threading; |
@@ -1825,6 +1826,170 @@ public Task<SeveralAudioFeatures> GetSeveralAudioFeaturesAsync(List<string> ids) |
1825 | 1826 |
|
1826 | 1827 | #endregion Tracks |
1827 | 1828 |
|
| 1829 | + #region Player |
| 1830 | + |
| 1831 | + /// <summary> |
| 1832 | + /// Get information about a user’s available devices. |
| 1833 | + /// </summary> |
| 1834 | + /// <returns></returns> |
| 1835 | + public AvailabeDevices GetDevices() |
| 1836 | + { |
| 1837 | + return DownloadData<AvailabeDevices>(_builder.GetDevices()); |
| 1838 | + } |
| 1839 | + |
| 1840 | + /// <summary> |
| 1841 | + /// Get information about the user’s current playback state, including track, track progress, and active device. |
| 1842 | + /// </summary> |
| 1843 | + /// <param name="market">An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking.</param> |
| 1844 | + /// <returns></returns> |
| 1845 | + public PlaybackContext GetPlayback(string market = "") |
| 1846 | + { |
| 1847 | + return DownloadData<PlaybackContext>(_builder.GetPlayback(market)); |
| 1848 | + } |
| 1849 | + |
| 1850 | + /// <summary> |
| 1851 | + /// Get the object currently being played on the user’s Spotify account. |
| 1852 | + /// </summary> |
| 1853 | + /// <param name="market">An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking.</param> |
| 1854 | + /// <returns></returns> |
| 1855 | + public PlaybackContext GetPlayingTrack(string market = "") |
| 1856 | + { |
| 1857 | + return DownloadData<PlaybackContext>(_builder.GetPlayingTrack(market)); |
| 1858 | + } |
| 1859 | + |
| 1860 | + /// <summary> |
| 1861 | + /// Transfer playback to a new device and determine if it should start playing. |
| 1862 | + /// </summary> |
| 1863 | + /// <param name="deviceId">ID of the device on which playback should be started/transferred to</param> |
| 1864 | + /// <param name="play"> |
| 1865 | + /// true: ensure playback happens on new device. |
| 1866 | + /// false or not provided: keep the current playback state. |
| 1867 | + /// </param> |
| 1868 | + /// <returns></returns> |
| 1869 | + public ErrorResponse TransferPlayback(string deviceId, bool play = false) => TransferPlayback( |
| 1870 | + new List<string> { deviceId }, play); |
| 1871 | + |
| 1872 | + /// <summary> |
| 1873 | + /// Transfer playback to a new device and determine if it should start playing. |
| 1874 | + /// NOTE: Although an array is accepted, only a single device_id is currently supported. Supplying more than one will return 400 Bad Request |
| 1875 | + /// </summary> |
| 1876 | + /// <param name="deviceIds">A array containing the ID of the device on which playback should be started/transferred.</param> |
| 1877 | + /// <param name="play"> |
| 1878 | + /// true: ensure playback happens on new device. |
| 1879 | + /// false or not provided: keep the current playback state. |
| 1880 | + /// </param> |
| 1881 | + /// <returns></returns> |
| 1882 | + public ErrorResponse TransferPlayback(List<string> deviceIds, bool play = false) |
| 1883 | + { |
| 1884 | + JObject ob = new JObject() |
| 1885 | + { |
| 1886 | + { "play", play }, |
| 1887 | + { "device_ids", new JArray(deviceIds) } |
| 1888 | + }; |
| 1889 | + return UploadData<ErrorResponse>(_builder.TransferPlayback(), ob.ToString(Formatting.None), "PUT"); |
| 1890 | + } |
| 1891 | + |
| 1892 | + /// <summary> |
| 1893 | + /// Start a new context or resume current playback on the user’s active device. |
| 1894 | + /// </summary> |
| 1895 | + /// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param> |
| 1896 | + /// <param name="contextUri">Spotify URI of the context to play.</param> |
| 1897 | + /// <param name="uris">A JSON array of the Spotify track URIs to play.</param> |
| 1898 | + /// <param name="offset">Indicates from where in the context playback should start. |
| 1899 | + /// Only available when context_uri corresponds to an album or playlist object, or when the uris parameter is used.</param> |
| 1900 | + /// <returns></returns> |
| 1901 | + public ErrorResponse ResumePlayback(string deviceId = "", string contextUri = "", List<string> uris = null, |
| 1902 | + int? offset = null) |
| 1903 | + { |
| 1904 | + JObject ob = new JObject(); |
| 1905 | + if(!string.IsNullOrEmpty(contextUri)) |
| 1906 | + ob.Add("context_uri", contextUri); |
| 1907 | + if(uris != null) |
| 1908 | + ob.Add("uris", new JArray(uris)); |
| 1909 | + if(offset != null) |
| 1910 | + ob.Add("offset", offset); |
| 1911 | + return UploadData<ErrorResponse>(_builder.ResumePlayback(deviceId), ob.ToString(Formatting.None), "PUT"); |
| 1912 | + } |
| 1913 | + |
| 1914 | + /// <summary> |
| 1915 | + /// Pause playback on the user’s account. |
| 1916 | + /// </summary> |
| 1917 | + /// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param> |
| 1918 | + /// <returns></returns> |
| 1919 | + public ErrorResponse PausePlayback(string deviceId = "") |
| 1920 | + { |
| 1921 | + return UploadData<ErrorResponse>(_builder.PausePlayback(deviceId), string.Empty, "PUT"); |
| 1922 | + } |
| 1923 | + |
| 1924 | + /// <summary> |
| 1925 | + /// Skips to next track in the user’s queue. |
| 1926 | + /// </summary> |
| 1927 | + /// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param> |
| 1928 | + /// <returns></returns> |
| 1929 | + public ErrorResponse SkipPlaybackToNext(string deviceId = "") |
| 1930 | + { |
| 1931 | + return UploadData<ErrorResponse>(_builder.SkipPlaybackToNext(deviceId), string.Empty); |
| 1932 | + } |
| 1933 | + |
| 1934 | + /// <summary> |
| 1935 | + /// Skips to previous track in the user’s queue. |
| 1936 | + /// Note that this will ALWAYS skip to the previous track, regardless of the current track’s progress. |
| 1937 | + /// Returning to the start of the current track should be performed using the https://api.spotify.com/v1/me/player/seek endpoint. |
| 1938 | + /// </summary> |
| 1939 | + /// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param> |
| 1940 | + /// <returns></returns> |
| 1941 | + public ErrorResponse SkipPlaybackToPrevious(string deviceId = "") |
| 1942 | + { |
| 1943 | + return UploadData<ErrorResponse>(_builder.SkipPlaybackToPrevious(deviceId), string.Empty); |
| 1944 | + } |
| 1945 | + |
| 1946 | + /// <summary> |
| 1947 | + /// Seeks to the given position in the user’s currently playing track. |
| 1948 | + /// </summary> |
| 1949 | + /// <param name="positionMs">The position in milliseconds to seek to. Must be a positive number. |
| 1950 | + /// Passing in a position that is greater than the length of the track will cause the player to start playing the next song.</param> |
| 1951 | + /// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param> |
| 1952 | + /// <returns></returns> |
| 1953 | + public ErrorResponse SeekPlayback(int positionMs, string deviceId = "") |
| 1954 | + { |
| 1955 | + return UploadData<ErrorResponse>(_builder.SeekPlayback(positionMs, deviceId), string.Empty); |
| 1956 | + } |
| 1957 | + |
| 1958 | + /// <summary> |
| 1959 | + /// Set the repeat mode for the user’s playback. Options are repeat-track, repeat-context, and off. |
| 1960 | + /// </summary> |
| 1961 | + /// <param name="state">track, context or off. </param> |
| 1962 | + /// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param> |
| 1963 | + /// <returns></returns> |
| 1964 | + public ErrorResponse SetRepeatMode(RepeatState state, string deviceId = "") |
| 1965 | + { |
| 1966 | + return UploadData<ErrorResponse>(_builder.SetRepeatMode(state, deviceId), string.Empty); |
| 1967 | + } |
| 1968 | + |
| 1969 | + /// <summary> |
| 1970 | + /// Set the volume for the user’s current playback device. |
| 1971 | + /// </summary> |
| 1972 | + /// <param name="volumePercent">Integer. The volume to set. Must be a value from 0 to 100 inclusive.</param> |
| 1973 | + /// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param> |
| 1974 | + /// <returns></returns> |
| 1975 | + public ErrorResponse SetVolume(int volumePercent, string deviceId = "") |
| 1976 | + { |
| 1977 | + return UploadData<ErrorResponse>(_builder.SetVolume(volumePercent, deviceId), string.Empty); |
| 1978 | + } |
| 1979 | + |
| 1980 | + /// <summary> |
| 1981 | + /// Toggle shuffle on or off for user’s playback. |
| 1982 | + /// </summary> |
| 1983 | + /// <param name="shuffle">True or False</param> |
| 1984 | + /// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param> |
| 1985 | + /// <returns></returns> |
| 1986 | + public ErrorResponse SetShuffle(bool shuffle, string deviceId = "") |
| 1987 | + { |
| 1988 | + return UploadData<ErrorResponse>(_builder.SetShuffle(shuffle, deviceId), string.Empty); |
| 1989 | + } |
| 1990 | + |
| 1991 | + #endregion |
| 1992 | + |
1828 | 1993 | #region Util |
1829 | 1994 |
|
1830 | 1995 | public TOut GetNextPage<TOut, TIn>(Paging<TIn> paging) where TOut : BasicModel |
|
0 commit comments