mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-24 06:56:27 +00:00
340 lines
14 KiB
HTML
340 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<meta name="author" content="JohnnyCrazy">
|
|
|
|
<link rel="shortcut icon" href="../img/favicon.ico">
|
|
|
|
<title>SpotifyLocalAPI - SpotifyAPI-NET</title>
|
|
|
|
<link href="../css/bootstrap-custom.min.css" rel="stylesheet">
|
|
<link href="../css/font-awesome-4.0.3.css" rel="stylesheet">
|
|
<link href="../css/prettify-1.0.css" rel="stylesheet">
|
|
<link href="../css/base.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/styles/agate.min.css">
|
|
|
|
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
|
|
<!--[if lt IE 9]>
|
|
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
|
|
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
|
|
<![endif]-->
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
|
|
<div class="container">
|
|
|
|
<!-- Collapsed navigation -->
|
|
<div class="navbar-header">
|
|
<!-- Expander button -->
|
|
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
|
|
<span class="sr-only">Toggle navigation</span>
|
|
<span class="icon-bar"></span>
|
|
<span class="icon-bar"></span>
|
|
<span class="icon-bar"></span>
|
|
</button>
|
|
|
|
<!-- Main title -->
|
|
<a class="navbar-brand" href="..">SpotifyAPI-NET</a>
|
|
</div>
|
|
|
|
<!-- Expanded navigation -->
|
|
<div class="navbar-collapse collapse">
|
|
<!-- Main navigation -->
|
|
<ul class="nav navbar-nav">
|
|
|
|
|
|
<li >
|
|
<a href="..">Home</a>
|
|
</li>
|
|
|
|
|
|
|
|
<li class="dropdown">
|
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown">SpotifyWebAPI <b class="caret"></b></a>
|
|
<ul class="dropdown-menu">
|
|
|
|
<li >
|
|
<a href="../SpotifyWebAPI/gettingstarted/">Getting started</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../SpotifyWebAPI/examples/">Examples</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../SpotifyWebAPI/auth/">Authentication</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../SpotifyWebAPI/proxy/">Proxy</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../SpotifyWebAPI/albums/">- Albums</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../SpotifyWebAPI/artists/">- Artists</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../SpotifyWebAPI/browse/">- Browse</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../SpotifyWebAPI/follow/">- Follow</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../SpotifyWebAPI/library/">- Library</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../SpotifyWebAPI/personalization/">- Personalization</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../SpotifyWebAPI/player/">- Player</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../SpotifyWebAPI/playlists/">- Playlists</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../SpotifyWebAPI/profiles/">- Profiles</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../SpotifyWebAPI/search/">- Search</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../SpotifyWebAPI/tracks/">- Tracks</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../SpotifyWebAPI/util/">- Util</a>
|
|
</li>
|
|
|
|
</ul>
|
|
</li>
|
|
|
|
|
|
|
|
<li class="active">
|
|
<a href="./">SpotifyLocalAPI</a>
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- Search, Navigation and Repo links -->
|
|
<ul class="nav navbar-nav navbar-right">
|
|
|
|
<li >
|
|
<a rel="next" href="../SpotifyWebAPI/util/">
|
|
<i class="fa fa-arrow-left"></i> Previous
|
|
</a>
|
|
</li>
|
|
<li class="disabled">
|
|
<a rel="prev" >
|
|
Next <i class="fa fa-arrow-right"></i>
|
|
</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="https://github.com/JohnnyCrazy/SpotifyAPI-NET">
|
|
|
|
<i class="fa fa-github"></i>
|
|
|
|
GitHub
|
|
</a>
|
|
</li>
|
|
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="container">
|
|
<div class="col-md-3"><div class="bs-sidebar hidden-print affix well" role="complementary" style="height=90%;">
|
|
<ul class="nav bs-sidenav">
|
|
|
|
<li class="main active"><a href="#getting-started">Getting started</a></li>
|
|
|
|
<li><a href="#first-steps">First steps</a></li>
|
|
|
|
<li><a href="#configuration">Configuration</a></li>
|
|
|
|
<li><a href="#proxy-settings">Proxy Settings</a></li>
|
|
|
|
<li><a href="#anti-virus-blocking-response">Anti-Virus Blocking Response</a></li>
|
|
|
|
<li><a href="#client-status">Client Status</a></li>
|
|
|
|
<li><a href="#current-track">Current Track</a></li>
|
|
|
|
<li><a href="#events">Events</a></li>
|
|
|
|
<li><a href="#methods">Methods</a></li>
|
|
|
|
|
|
</ul>
|
|
</div></div>
|
|
<div class="col-md-9" role="main">
|
|
|
|
<h1 id="getting-started">Getting started</h1>
|
|
<p>This API provides some access to the local running Spotify-Client (Windows only).<br />
|
|
You can fetch details for the current track, play/pause, skip/previous track and
|
|
get notified on various events.</p>
|
|
<p><strong>NOTE:</strong> This API is unofficial, things may break in the future and there is no
|
|
guarantee everything works out of the box.</p>
|
|
<hr />
|
|
<h2 id="first-steps">First steps</h2>
|
|
<p><strong>Imports</strong><br />
|
|
So after you added the API to your project, you may want to add following imports to your files:</p>
|
|
<pre><code class="cs">using SpotifyAPI.Local; //Base Namespace
|
|
using SpotifyAPI.Local.Enums; //Enums
|
|
using SpotifyAPI.Local.Models; //Models for the JSON-responses
|
|
</code></pre>
|
|
|
|
<p><strong>Basic-Usage</strong><br />
|
|
Now you can actually start fetching infos from your spotify client, just create a new Instance of SpotifyLocalAPI:</p>
|
|
<pre><code class="cs">private static SpotifyLocalAPI _spotify;
|
|
|
|
public static void Main(String[] args)
|
|
{
|
|
_spotify = new SpotifyLocalAPI();
|
|
if (!SpotifyLocalAPI.IsSpotifyRunning())
|
|
return; //Make sure the spotify client is running
|
|
if (!SpotifyLocalAPI.IsSpotifyWebHelperRunning())
|
|
return; //Make sure the WebHelper is running
|
|
|
|
if(!_spotify.Connect())
|
|
return; //We need to call Connect before fetching infos, this will handle Auth stuff
|
|
|
|
StatusResponse status = _spotify.GetStatus(); //status contains infos
|
|
}
|
|
</code></pre>
|
|
|
|
<h2 id="configuration">Configuration</h2>
|
|
<p>Different spotify versions often require different configuration. Some versions run their web-helper on port <code>4371</code>, others on <code>4381</code> or <code>4380</code>. Also, some use <code>https</code>, and others use <code>http</code>. You can use <code>SpotifyLocalAPIConfig</code> to configure the API:</p>
|
|
<pre><code class="cs">_spotify = new SpotifyLocalAPI(new SpotifyLocalAPIConfig
|
|
{
|
|
Port = 4371,
|
|
HostUrl = "https://127.0.0.1"
|
|
});
|
|
</code></pre>
|
|
|
|
<h2 id="proxy-settings">Proxy Settings</h2>
|
|
<p>You can forward your proxy settings to the local api by using a field in the <code>SpotifyLocalAPIConfig</code>.</p>
|
|
<pre><code class="cs">_spotify = new SpotifyLocalAPI(new SpotifyLocalAPIConfig
|
|
{
|
|
ProxyConfig = new ProxyConfig() {
|
|
Host = "127.0.0.1",
|
|
Port = 8080
|
|
// Additional values like Username and Password are available
|
|
}
|
|
});
|
|
</code></pre>
|
|
|
|
<h2 id="anti-virus-blocking-response">Anti-Virus Blocking Response</h2>
|
|
<p>Some Anti-Virus Software blocks the response from spotify due wrong headers.
|
|
Currently, it's confirmed for AVG's LinkScanner and Bitdefender.
|
|
Adding <code>http://SpotifyAPI.spotilocal.com:4380</code> to the URL-Exceptions seems to fix it for most users.
|
|
More infos can be found <a href="https://github.com/JohnnyCrazy/SpotifyAPI-NET/issues/51">here</a></p>
|
|
<h2 id="client-status">Client Status</h2>
|
|
<p>Calling <code>_spotify.GetStatus()</code> after connecting returns the following <code>StatusResponse</code>:</p>
|
|
<pre><code>public int Version { get; set; }
|
|
|
|
public string ClientVersion { get; set; }
|
|
|
|
public bool Playing { get; set; }
|
|
|
|
public bool Shuffle { get; set; }
|
|
|
|
public bool Repeat { get; set; }
|
|
|
|
public bool PlayEnabled { get; set; }
|
|
|
|
public bool PrevEnabled { get; set; }
|
|
|
|
public bool NextEnabled { get; set; }
|
|
|
|
public Track Track { get; set; }
|
|
|
|
public double PlayingPosition { get; set; }
|
|
|
|
public int ServerTime { get; set; }
|
|
|
|
public double Volume { get; set; }
|
|
|
|
public bool Online { get; set; }
|
|
|
|
public bool Running { get; set; }
|
|
</code></pre>
|
|
|
|
<p>Most of the properties are self-explanatory, some notes:</p>
|
|
<ul>
|
|
<li><code>Shuffle</code> and <code>Repeat</code> currently always return <code>false</code></li>
|
|
</ul>
|
|
<h2 id="current-track">Current Track</h2>
|
|
<p>The current Track can be fetched via <code>_spotify.GetStatus().Track</code> and contains following properties/methods:</p>
|
|
<ul>
|
|
<li><code>TrackResource</code> - <code>SpotifyResource</code> which contains Track <code>Name</code> and <code>Uri</code></li>
|
|
<li><code>AlbumResource</code> - <code>SpotifyResource</code> which contains Album <code>Name</code> and <code>Uri</code></li>
|
|
<li><code>ArtistResource</code> - <code>SpotifyResource</code> which contains Artist <code>Name</code> and <code>Uri</code> (Only the main artist will be listed)</li>
|
|
<li><code>IsAd()</code> will check whether the current track is an AD</li>
|
|
<li>Various methods for getting the album art:</li>
|
|
<li><code>string GetAlbumArtUrl(AlbumArtSize size)</code></li>
|
|
<li><code>Task<Bitmap> GetAlbumArtAsync(AlbumArtSize size)</code></li>
|
|
<li><code>Bitmap GetAlbumArt(AlbumArtSize size)</code></li>
|
|
<li><code>Task<byte[]> GetAlbumArtAsByteArrayAsync(AlbumArtSize size)</code></li>
|
|
<li><code>byte[] GetAlbumArtAsByteArray(AlbumArtSize size)</code></li>
|
|
</ul>
|
|
<h2 id="events">Events</h2>
|
|
<p>To receive events, make sure you listen for them <code>_spotify.ListenForEvents = true;</code><br />
|
|
You can set a <code>SynchronizingObject</code>, then the events will be called on the specific context</p>
|
|
<p>Following events can be overriden:</p>
|
|
<ul>
|
|
<li><code>OnPlayStateChange</code> - triggers when the player changes from <code>play</code> to <code>pause</code> and vice versa</li>
|
|
<li><code>OnTrackChange</code> - triggers when a new track will be played</li>
|
|
<li><code>OnTrackTimeChange</code> - triggers when a track is playing and track-time changes</li>
|
|
<li><code>OnVolumeChange</code> - triggeres when the internal volume of spotify changes</li>
|
|
</ul>
|
|
<h2 id="methods">Methods</h2>
|
|
<p>Furthermore, following methods are available:</p>
|
|
<ul>
|
|
<li><code>void Mute()</code> - will mute the Spotify client via WindowsAPI</li>
|
|
<li><code>void UnMute()</code> - will unmute the Spotify client via WindowsAPI</li>
|
|
<li><code>bool IsSpotifyMuted()</code> - will return wether the Spotify client is muted</li>
|
|
<li><code>void SetSpotifyVolume(float volume = 100)</code> - sets the windows volume of spotify (0 - 100)</li>
|
|
<li><code>float GetSpotifyVolume()</code> - returns the windows volume of spotify (0 - 100)</li>
|
|
<li><code>void Pause()</code> - will pause spotify's playback</li>
|
|
<li><code>void Play()</code> - will resume spotify's playback</li>
|
|
<li><code>void PlayURL(string uri, string context = "")</code> - will play a spotify URI (track/album/playlist) in the specifc context (can be a album/playlist URI)</li>
|
|
<li><code>void Skip()</code> - will skip the track via an emulated media key</li>
|
|
<li><code>void Previous()</code> - will play the previous track via an emulated media key</li>
|
|
<li><code>bool IsSpotifyRunning()</code> - returns true if a spotify client instance is running, false if not</li>
|
|
<li><code>bool IsSpotifyWebHelperRunning()</code> - returns true if a spotify web-helper instance is running, false if not</li>
|
|
<li><code>void RunSpotify()</code> - will attempt to start a Spotify instance</li>
|
|
<li><code>void RunSpotifyWebHelper()</code> - will attempt to start a Spotify web-helper instance</li>
|
|
</ul></div>
|
|
</div>
|
|
|
|
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/highlight.min.js"></script>
|
|
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
|
|
<script src="../js/bootstrap-3.0.3.min.js"></script>
|
|
<script src="../js/base.js"></script>
|
|
<script src="../highlight.js"></script>
|
|
</body>
|
|
</html> |