SPTAudioStreamingController Class Reference
Inherits from | NSObject |
Declared in | SPTAudioStreamingController.h |
Overview
This class manages audio streaming from Spotify.
Note: There must be only one concurrent instance of this class in your app.
Tasks
Initialisation and Setup
-
+ sharedInstance
-
– startWithClientId:audioController:allowCaching:error:
-
– startWithClientId:error:
-
– stopWithError:
-
– loginWithAccessToken:
-
– logout
Properties
-
initialized
property -
loggedIn
property -
delegate
property -
playbackDelegate
property -
diskCache
property
Controlling Playback
-
– setVolume:callback:
-
– setTargetBitrate:callback:
-
– seekTo:callback:
-
– setIsPlaying:callback:
-
– playSpotifyURI:startingWithIndex:startingWithPosition:callback:
-
– queueSpotifyURI:callback:
-
– skipNext:
-
– skipPrevious:
-
– setShuffle:callback:
-
– setRepeat:callback:
-
volume
property -
metadata
property -
playbackState
property -
targetBitrate
property
Properties
delegate
The receiver’s delegate, which deals with session events such as login, logout, errors, etc.
@property (nonatomic, weak) id<SPTAudioStreamingDelegate> delegate
Declared In
SPTAudioStreamingController.h
diskCache
The object responsible for caching of audio data.
@property (nonatomic, strong) id<SPTDiskCaching> diskCache
Discussion
The object is an instance of a class that implements the SPTDiskCaching
protocol.
If nil
, no caching will be performed.
Declared In
SPTAudioStreamingController.h
initialized
YES while the SPTAudioStreamingController
is initialized
@property (atomic, readonly, assign) BOOL initialized
Declared In
SPTAudioStreamingController.h
loggedIn
Returns YES
if the receiver is logged into the Spotify service, otherwise NO
.
@property (atomic, readonly) BOOL loggedIn
Declared In
SPTAudioStreamingController.h
metadata
Metadata for the currently playing context
@property (atomic, readonly) SPTPlaybackMetadata *metadata
Declared In
SPTAudioStreamingController.h
playbackDelegate
The receiver’s playback delegate, which deals with audio playback events.
@property (nonatomic, weak) id<SPTAudioStreamingPlaybackDelegate> playbackDelegate
Declared In
SPTAudioStreamingController.h
playbackState
The players current state
@property (atomic, readonly) SPTPlaybackState *playbackState
Declared In
SPTAudioStreamingController.h
Instance Methods
loginWithAccessToken:
Log into the Spotify service for audio playback.
- (void)loginWithAccessToken:(NSString *)accessToken
Parameters
- accessToken
An authenticated access token authorized with the
streaming
scope.
Discussion
Audio playback will not be available until the receiver is successfully logged in.
Login is asynchronous.
Success will be notified on the audioStreamingDidLogin:
delegate method and
failure will be notified on the audioStreaming:didEncounterError:
delegate method.
Declared In
SPTAudioStreamingController.h
logout
Log out of the Spotify service
- (void)logout
Discussion
This method is asynchronous. When logout is complete you will be notified by the
audioStreamingDidLogout:
delegate method.
Declared In
SPTAudioStreamingController.h
playSpotifyURI:startingWithIndex:startingWithPosition:callback:
Play a Spotify URI.
- (void)playSpotifyURI:(NSString *)spotifyUri startingWithIndex:(NSUInteger)index startingWithPosition:(NSTimeInterval)position callback:(SPTErrorableOperationCallback)block
Parameters
- spotifyUri
The Spotify URI to play.
- index
The index of an item that should be played first, e.g. 0 - for the very first track in the playlist or a single track
- position
starting position for playback in sec
- block
The callback block to be executed when the playback command has been received, which will pass back an
NSError
object if an error ocurred.
Discussion
Supported URI types: Tracks, Albums and Playlists
Declared In
SPTAudioStreamingController.h
queueSpotifyURI:callback:
Queue a Spotify URI.
- (void)queueSpotifyURI:(NSString *)spotifyUri callback:(SPTErrorableOperationCallback)block
Parameters
- spotifyUri
The Spotify URI to queue.
- block
The callback block to be executed when the playback command has been received, which will pass back an
NSError
object if an error ocurred.
Discussion
Supported URI types: Tracks
Declared In
SPTAudioStreamingController.h
seekTo:callback:
Seek playback to a given location in the current track.
- (void)seekTo:(NSTimeInterval)position callback:(SPTErrorableOperationCallback)block
Parameters
- position
in sec to seek to.
- block
The callback block to be executed when the command has been received, which will pass back an
NSError
object if an error ocurred.
See Also
Declared In
SPTAudioStreamingController.h
setIsPlaying:callback:
Set the “playing” status of the receiver.
- (void)setIsPlaying:(BOOL)playing callback:(SPTErrorableOperationCallback)block
Parameters
- playing
Pass
YES
to resume playback, orNO
to pause it.
- block
The callback block to be executed when the command has been received, which will pass back an
NSError
object if an error ocurred.
See Also
Declared In
SPTAudioStreamingController.h
setRepeat:callback:
Set repeat state, on, off or repeat-one
- (void)setRepeat:(SPTRepeatMode)mode callback:(SPTErrorableOperationCallback)block
Parameters
- mode
The state to set, SPTRepeatOff, SPTRepeatContext or SPTRepeatOne.
- block
The callback block to be executed when the command has been received, which will pass back an
NSError
object if an error ocurred.
Declared In
SPTAudioStreamingController.h
setShuffle:callback:
Set state for shuffle, on or off.
- (void)setShuffle:(BOOL)enable callback:(SPTErrorableOperationCallback)block
Parameters
- enable
The state to set, YES to enable shuffle and NO to disable.
- block
The callback block to be executed when the command has been received, which will pass back an
NSError
object if an error ocurred.
Declared In
SPTAudioStreamingController.h
setTargetBitrate:callback:
Set the target streaming bitrate.
- (void)setTargetBitrate:(SPTBitrate)bitrate callback:(SPTErrorableOperationCallback)block
Parameters
- bitrate
The bitrate to target.
- block
The callback block to be executed when the command has been received, which will pass back an
NSError
object if an error ocurred.
Discussion
The library will attempt to stream audio at the given bitrate. If the given bitrate is not available, the closest match will be used. This process is completely transparent, but you should be aware that data usage isn’t guaranteed.
Declared In
SPTAudioStreamingController.h
setVolume:callback:
Set playback volume to the given level.
- (void)setVolume:(SPTVolume)volume callback:(SPTErrorableOperationCallback)block
Parameters
- volume
The volume to change to, as a value between
0.0
and1.0
.
- block
The callback block to be executed when the command has been received, which will pass back an
NSError
object if an error ocurred.
See Also
Declared In
SPTAudioStreamingController.h
skipNext:
Go to the next track in the queue.
- (void)skipNext:(SPTErrorableOperationCallback)block
Parameters
- block
The callback block to be executed when the command has been received, which will pass back an
NSError
object if an error ocurred.
Declared In
SPTAudioStreamingController.h
skipPrevious:
Go to the previous track in the queue
- (void)skipPrevious:(SPTErrorableOperationCallback)block
Parameters
- block
The callback block to be executed when the command has been received, which will pass back an
NSError
object if an error ocurred.
Declared In
SPTAudioStreamingController.h
startWithClientId:audioController:allowCaching:error:
Start the SPAudioStreamingController
thread with a custom audio controller.
- (BOOL)startWithClientId:(NSString *)clientId audioController:(SPTCoreAudioController *)audioController allowCaching:(BOOL)allowCaching error:(NSError *__autoreleasing *)error
Parameters
- clientId
Your client id found at developer.spotify.com
- audioController
Custom audio controller
- allowCaching
YES of persisten disk caching is allowed
- error
If method returns NO, error will be set
Return Value
Returns YES if initialization was successful
Discussion
Note: You MUST initialize the SPAudioStreamingController
sharedInstance before calling any other method.
Declared In
SPTAudioStreamingController.h
startWithClientId:error:
Start the SPAudioStreamingController
thread with the default audioController.
- (BOOL)startWithClientId:(NSString *)clientId error:(NSError *__autoreleasing *)error
Parameters
- clientId
Your client id found at developer.spotify.com
- error
If method returns NO, error will be set
Return Value
Returns YES if initialization was successful
Discussion
Note: You need to start the SPAudioStreamingController
sharedInstance before calling any other method.
Declared In
SPTAudioStreamingController.h