Skip to content

Allow MediaController to set local configuration (e.g. Uri) to start playback #282

@jakoss

Description

@jakoss

Media3 Version

Media3 1.0.0

Devices that reproduce the issue

  • Samsung Galaxy S21 FE
  • Any emulator i tried it on

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

Reproduction project: repro.zip

I created PlaybackService by mirroring the example from website:

class PlaybackService : MediaSessionService() {
    private var mediaSession: MediaSession? = null

    override fun onCreate() {
        super.onCreate()
        val player = ExoPlayer.Builder(this)
            .setMediaSourceFactory(
                DefaultMediaSourceFactory(this)
                    .setDataSourceFactory(
                        DefaultDataSource.Factory(
                            this,
                            OkHttpDataSource.Factory(OkHttpClient.Builder().build())
                        )
                    )
            )
            .build()
        player.addAnalyticsListener(EventLogger())
        mediaSession = MediaSession
            .Builder(this, player)
            .build()
    }

    override fun onGetSession(controllerInfo: MediaSession.ControllerInfo) = mediaSession

    override fun onDestroy() {
        mediaSession?.run {
            player.release()
            release()
            mediaSession = null
        }
        super.onDestroy()
    }
}

Then i setup MediaController in Activity like this:

override fun onStart() {
        super.onStart()
        val sessionToken = SessionToken(this@MainActivity, ComponentName(this@MainActivity, PlaybackService::class.java))
        val controllerFuture = MediaController.Builder(this, sessionToken).buildAsync()
        controllerFuture.addListener(
            { mediaController = controllerFuture.get() },
            MoreExecutors.directExecutor()
        )
    }

Then i try to set new item to play like this:

mediaController?.let {
                                it.setMediaItem(
                                    MediaItem.Builder()
                                        .setUri("https://demo.unified-streaming.com/k8s/features/stable/video/tears-of-steel/tears-of-steel.ism/.m3u8")
                                        .setMediaId("id")
                                        .setMediaMetadata(
                                            MediaMetadata.Builder()
                                                .setTitle("Test title")
                                                .setArtist("Test artist")
                                                .setArtworkUri("https://images.unsplash.com/photo-1679663877752-c00ad7f1c5c5?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2940&q=80".toUri())
                                                .build()
                                        )
                                        .build()
                                )
                                it.prepare()
                                it.play()
                            }

In attached reproduction app you can click "Play by service" and literally nothing happens (logs are empty too, even with EventLogger setup. It's seems like the command passed through, but the playback never started.

Playing via local exoplayer works properly as presented in the "Play locally" button

Expected result

I should be able to set new media item with HLS content via MediaController

Actual result

Nothing happens, log is empty. Player have no error. It seems like after trying to play item player instantly goes to ENDED state without particular reason

Media

https://demo.unified-streaming.com/k8s/features/stable/video/tears-of-steel/tears-of-steel.ism/.m3u8

Bug Report

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions