0

I am creating a music player like Spotify and was trying to achieve the functionality where the song continues getting played just above the BottomNavigationBar while navigating through the app and even when the activity/fragment which has the controls, album art and all is closed. So, when I tried to pass the instance of SimpleExoPlayer from the activity which initialized the player to the fragment in the home activity of my app through Intent like


...

override fun onBackPressed() {
        super.onBackPressed()

        val intent = Intent()
        intent.putExtra(RETURN_BACK_TO_LIBRARY_FRAG, TransferablePlayer(player as SimpleExoPlayer))
        setResult(101, intent)
        finish()
    }

...

TransferablePlayer is a Parcelable

...

@Parcelize
data class TransferablePlayer(val player: @RawValue SimpleExoPlayer): Parcelable

...

then I got the following error

java.lang.RuntimeException: Parcel: unable to marshal value com.google.android.exoplayer2.SimpleExoPlayer@91a2309

which simply means that SimpleExoPlayer class is not a Serializable and hence can not be passed through Intent.
Is there any way to move the same instance of SimpleExoPlayer around activities or is there any better approach to achieve the same results?

Neeraj Sewani
  • 3,952
  • 6
  • 38
  • 55

0 Answers0