Peter-Schorn / SpotifyAPIExampleApp

An Example App that demonstrates the usage of SpotifyAPI.
23 stars 8 forks source link

Difficulty using iPhone as the Device #6

Closed gmatrangola closed 1 year ago

gmatrangola commented 1 year ago

The Spotify App is frozen while the SpotifyAPIExampleApp (or any other app) is in the foreground. Thus you cannot initiate playback of a song using the SpotifyWebAPI play(PlaybackRequest, deviceID) where deviceID = the iPhone device ID. It seems that using the "official" Spotify ios API will allow an app to start playing on the iPhone device by switching to the Spotify App, initiating the playback, then control returns to the client app. What are the caveats and advantages of using both iOS Spotify API and the SpotifyWebAPI in the same app?

Peter-Schorn commented 1 year ago

The Spotify App is frozen while the SpotifyAPIExampleApp (or any other app) is in the foreground. Thus you cannot initiate playback of a song using the SpotifyWebAPI play(PlaybackRequest, deviceID) where deviceID = the iPhone device ID.

If the Spotify iOS app is playing music, then it will not be frozen in the background, in which case you can initiate web API playback commands targeting the current device.

It seems that using the "official" Spotify ios API will allow an app to start playing on the iPhone device by switching to the Spotify App, initiating the playback, then control returns to the client app.

I don't know what you mean by "official" Spotify ios API. You cannot use any web API to launch the Spotify iOS app to initiate playback. You can use the Spotify iOS SDK to do this, though. Are you thinking of Spotify's iOS siri integration? That's done using Apple's SiriKit framework.

What are the caveats and advantages of using both iOS Spotify API and the SpotifyWebAPI in the same app?

Please confirm that "iOS Spotify API" refers to the Spotify iOS SDK and "SpotifyWebAPI" refers to my SpotifyAPI library. (If so, please use these terms instead for clarity.)

gmatrangola commented 1 year ago

Yes, I meant that the Spotify App freezes when no music is playing and it is not the foreground app. So, I was having difficulty using your SpotifyAPI to initiate playback on the "iPhone" device when that was the state. Yes, I was referring to the Spotify iOS SDK https://github.com/spotify/ios-sdk when I said "official", Not the Siri integration.

Peter-Schorn commented 1 year ago

Assuming your question is: What are the caveats and advantages of using both the Spotify web API and the Spotify iOS SDK in the same app:

The main features that the Spotify iOS SDK has that the web API doesn't are the ability to play content while offline and the ability to launch the Spotify iOS app to play content.

Peter-Schorn commented 1 year ago

I'm curious as to why I need a server?

See this alternative authorization method. It's required if you want to authorize without starting playback. A more important benefit, which is not mentioned explicitly, is that, with this authorization method exclusively, you can provide the same scopes that you would when using the spotify web API and get an access and refresh token that can be used with the web API.

If you look at Model/Spotify.swift, you'll see how tightly integrated SpotifyAPI and the Spotify iOS SDK are. For example, the access token is obtained using the Spotify iOS SDK and used by both it and SpotifyAPI.

gmatrangola commented 1 year ago

Thanks for your continued support on this. In order for me to better understand the interactions between the Spotify iOS SDK and SwiftUI, I created a sample program that is similar to the UIKit version that they created but uses SwiftUI instead. The repo is here: SpotifyRemoteSwiftUI