Search code examples
swiftspotifylibspotifycocoalibspotify-2.0spotify-desktop

How to lower or higher the volume of music in Spotify SDK Swift


I'm working on a simple app that allows a user to sign in with his/her spotify account and then plays a song after user authentication. I tried following the spotify-provided tutorial, but i am really confused how to get volume and how to set low or high volume of music. I found two function method:

First function

func audioStreaming(_ audioStreaming: SPTAudioStreamingController!, didSeekToPosition position: TimeInterval) {
}  

Second function

func audioStreaming(_ audioStreaming: SPTAudioStreamingController!, didChangeVolume volume: SPTVolume) {
}

But i am confused how to use this function and how to get volume through this functions? if any other function through get volume or set high or low volume please let me known.

Can someone please explain to me how to solve this , i've tried to solve this issue but no results yet.

Any help would be greatly appreciated.

Thank you.


Solution

  • volume is a property on SPTAudioStreamingController object, so to get the current volume you simply need to get a reference to your SPTAudioStreamingController and then read the volume off of that.

    Then, to reset the volume, you can use SPTAudioStreamingController's setVolume:callback: function.

    And if it works, I suspect that second delegate method you pointed to in your question will fire, but you can also use the callback to detect whether an error happened.