Spotify-SDK-Swift-Tutorial-Part-One icon indicating copy to clipboard operation
Spotify-SDK-Swift-Tutorial-Part-One copied to clipboard

spotify track is not playing after I stopped `MPMusicPlayerController.systemMusicPlayer` track

Open Ilesh opened this issue 6 years ago • 0 comments

In my application, I am using MPMusicPlayerController.systemMusicPlayer for the playing song of Apple music, it's working fine. But when I play back Spotify track using playSpotifyURI it's not working. I have checked logs but not showing error anywhere.

Scenario Step 1. Play track using playSpotifyURI. It is playing fine

SPTAudioStreamingController.sharedInstance().playSpotifyURI(itemID, startingWith: 0, startingWithPosition: 0) { error in
            if error != nil {
                print("*** failed to play: \(String(describing: error))")
                return
            }else{
                print("Playing!!")
            }
        }

Step 2. stop track using.

SPTAudioStreamingController.sharedInstance().setIsPlaying(false, callback: { (error) in
                                
                            })

Step 3. play apple music song using theMPMusicPlayerController.systemMusicPlayer

func beginPlayback(itemID: String) {
        if musicPlayerController.playbackState == .playing {
            musicPlayerController.stop()
        }
        //musicPlayerController.setQueue(with: [itemID]) //1324456545
        musicPlayerController.setQueue(with: [itemID])
        musicPlayerController.prepareToPlay { (error) in
            print("prepareToPlay----------------")
        }
        musicPlayerController.play()
    }

Step 4. Stop Apple music song using.

if musicPlayerController.playbackState == .playing {
            musicPlayerController.stop()
        }

Step 5. Play track using playSpotifyURI using below code but it's not playing, I couldn't find any error.

SPTAudioStreamingController.sharedInstance().playSpotifyURI(itemID, startingWith: 0, startingWithPosition: 0) { error in
            if error != nil {
                print("*** failed to play: \(String(describing: error))")
                return
            }else{
                print("Playing!!")
            }
        }

Is there any issue of the above code? Please help me to solve an issue. Any help will be appreciated

Ilesh avatar Oct 15 '18 05:10 Ilesh