Announcements

Help Wizard

Step 1

NEXT STEP

How to play music with endpoint me/player/play in jetpackcompose

How to play music with endpoint me/player/play in jetpackcompose

@Headers("Authorization: Bearer ${Constants.AUTHORIZATION_HEADER}")
@PUT("v1/me/player/play")
fun play(
@Header("Content-Type") contentType: String,
@Body body: PlayRequestBody
) : Call<Void>

ViewModel
fun playMusic(contextUri: String) {

val requestBody = PlayRequestBody(
context_uri = "spotify:album:5ht7ItJgpBH7W6vJ5BqpPr",
offset = Offset(position = 5),
position_ms = 0
)
soundSphereApiService.play(contentType = "application/json", body = requestBody).enqueue(object : Callback<Void> {
override fun onResponse(call: Call<Void>, response: Response<Void>) {
Log.d("PlayViewModel", "playMusic: ${response.isSuccessful}")
if (response.isSuccessful) {
Log.d("PlayViewModel", "playMusic: ${response.body().toString()}")
} else {
Log.e("PlayViewModel", "playMusic: ${response.code()}")
}
}

override fun onFailure(call: Call<Void>, t: Throwable) {
//Log.e("PlayViewModel", "playMusic: ${t.message}")
}
})
} 

 

Reply
1 Reply

I don't have knowledge of jetpackcompose, but one thing I know is that a access token you got from the first tutorial or the client credentials flow won't work. You should get an access token through another OAuth flow instead 

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Suggested posts

Let's introduce ourselves!

Hey there you,   Yeah, you! 😁   Welcome - we're glad you joined the Spotify Community!   While you here, let's have a fun game and get…

ModeratorStaff / Moderator/ 4 years ago  in Social & Random