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
-
initializedproperty -
loggedInproperty -
delegateproperty -
playbackDelegateproperty -
diskCacheproperty
Controlling Playback
-
– setVolume:callback: -
– setTargetBitrate:callback: -
– seekTo:callback: -
– setIsPlaying:callback: -
– playSpotifyURI:startingWithIndex:startingWithPosition:callback: -
– queueSpotifyURI:callback: -
– skipNext: -
– skipPrevious: -
– setShuffle:callback: -
– setRepeat:callback: -
volumeproperty -
metadataproperty -
playbackStateproperty -
targetBitrateproperty
Properties
delegate
The receiver’s delegate, which deals with session events such as login, logout, errors, etc.
@property (nonatomic, weak) id<SPTAudioStreamingDelegate> delegateDeclared In
SPTAudioStreamingController.hdiskCache
The object responsible for caching of audio data.
@property (nonatomic, strong) id<SPTDiskCaching> diskCacheDiscussion
The object is an instance of a class that implements the SPTDiskCaching protocol.
If nil, no caching will be performed.
Declared In
SPTAudioStreamingController.hinitialized
YES while the SPTAudioStreamingController is initialized
@property (atomic, readonly, assign) BOOL initializedDeclared In
SPTAudioStreamingController.hloggedIn
Returns YES if the receiver is logged into the Spotify service, otherwise NO.
@property (atomic, readonly) BOOL loggedInDeclared In
SPTAudioStreamingController.hmetadata
Metadata for the currently playing context
@property (atomic, readonly) SPTPlaybackMetadata *metadataDeclared In
SPTAudioStreamingController.hplaybackDelegate
The receiver’s playback delegate, which deals with audio playback events.
@property (nonatomic, weak) id<SPTAudioStreamingPlaybackDelegate> playbackDelegateDeclared In
SPTAudioStreamingController.hplaybackState
The players current state
@property (atomic, readonly) SPTPlaybackState *playbackStateDeclared In
SPTAudioStreamingController.hInstance Methods
loginWithAccessToken:
Log into the Spotify service for audio playback.
- (void)loginWithAccessToken:(NSString *)accessTokenParameters
- accessToken
An authenticated access token authorized with the
streamingscope.
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.hlogout
Log out of the Spotify service
- (void)logoutDiscussion
This method is asynchronous. When logout is complete you will be notified by the
audioStreamingDidLogout: delegate method.
Declared In
SPTAudioStreamingController.hplaySpotifyURI:startingWithIndex:startingWithPosition:callback:
Play a Spotify URI.
- (void)playSpotifyURI:(NSString *)spotifyUri startingWithIndex:(NSUInteger)index startingWithPosition:(NSTimeInterval)position callback:(SPTErrorableOperationCallback)blockParameters
- 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
NSErrorobject if an error ocurred.
Discussion
Supported URI types: Tracks, Albums and Playlists
Declared In
SPTAudioStreamingController.hqueueSpotifyURI:callback:
Queue a Spotify URI.
- (void)queueSpotifyURI:(NSString *)spotifyUri callback:(SPTErrorableOperationCallback)blockParameters
- 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
NSErrorobject if an error ocurred.
Discussion
Supported URI types: Tracks
Declared In
SPTAudioStreamingController.hseekTo:callback:
Seek playback to a given location in the current track.
- (void)seekTo:(NSTimeInterval)position callback:(SPTErrorableOperationCallback)blockParameters
- position
in sec to seek to.
- block
The callback block to be executed when the command has been received, which will pass back an
NSErrorobject if an error ocurred.
See Also
Declared In
SPTAudioStreamingController.hsetIsPlaying:callback:
Set the “playing” status of the receiver.
- (void)setIsPlaying:(BOOL)playing callback:(SPTErrorableOperationCallback)blockParameters
- playing
Pass
YESto resume playback, orNOto pause it.
- block
The callback block to be executed when the command has been received, which will pass back an
NSErrorobject if an error ocurred.
See Also
Declared In
SPTAudioStreamingController.hsetRepeat:callback:
Set repeat state, on, off or repeat-one
- (void)setRepeat:(SPTRepeatMode)mode callback:(SPTErrorableOperationCallback)blockParameters
- 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
NSErrorobject if an error ocurred.
Declared In
SPTAudioStreamingController.hsetShuffle:callback:
Set state for shuffle, on or off.
- (void)setShuffle:(BOOL)enable callback:(SPTErrorableOperationCallback)blockParameters
- 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
NSErrorobject if an error ocurred.
Declared In
SPTAudioStreamingController.hsetTargetBitrate:callback:
Set the target streaming bitrate.
- (void)setTargetBitrate:(SPTBitrate)bitrate callback:(SPTErrorableOperationCallback)blockParameters
- bitrate
The bitrate to target.
- block
The callback block to be executed when the command has been received, which will pass back an
NSErrorobject 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.hsetVolume:callback:
Set playback volume to the given level.
- (void)setVolume:(SPTVolume)volume callback:(SPTErrorableOperationCallback)blockParameters
- volume
The volume to change to, as a value between
0.0and1.0.
- block
The callback block to be executed when the command has been received, which will pass back an
NSErrorobject if an error ocurred.
See Also
Declared In
SPTAudioStreamingController.hskipNext:
Go to the next track in the queue.
- (void)skipNext:(SPTErrorableOperationCallback)blockParameters
- block
The callback block to be executed when the command has been received, which will pass back an
NSErrorobject if an error ocurred.
Declared In
SPTAudioStreamingController.hskipPrevious:
Go to the previous track in the queue
- (void)skipPrevious:(SPTErrorableOperationCallback)blockParameters
- block
The callback block to be executed when the command has been received, which will pass back an
NSErrorobject if an error ocurred.
Declared In
SPTAudioStreamingController.hstartWithClientId: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 *)errorParameters
- 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.hstartWithClientId:error:
Start the SPAudioStreamingController thread with the default audioController.
- (BOOL)startWithClientId:(NSString *)clientId error:(NSError *__autoreleasing *)errorParameters
- 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