Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

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