androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Audio files less than 1 second do not always trigger onMediaItemTransition

aljohnston112 opened this issue · comments

Version

Media3 1.2.0

More version details

Forgive me if this is fixed, I am waiting for 1.4.0-alpha02 to be released in a stable release. #1352.

I wrote a test that uses very short audio files. One is 7.34kB and the other is 7.15kB. They are both mp3 files and they trigger onMediaItemTransition about only 10% of the time.

This is the listener code

override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) {
    super.onMediaItemTransition(mediaItem, reason)
    if (reason == MEDIA_ITEM_TRANSITION_REASON_AUTO) {
        val id = mediaItem!!.mediaId.toLong()
        observedCounts[id] = (observedCounts[id] ?: 0L) + 1
        countDownLatch.countDown()
    }
}

I add media item this way

    override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) {
        super.onMediaItemTransition(mediaItem, reason)
        scope.launch(Dispatchers.Main.immediate) {
            if (reason == Player.MEDIA_ITEM_TRANSITION_REASON_AUTO) {
                addMediaItem(
                    getNextSong(playlistProvider.await())
                )
            }
        }
    }

Devices that reproduce the issue

Pixel 8 running Android 14

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

Attach listeners that override onMediaItemTransition to the Player. One listener adds one of two very short mp3 files every time the current one finishes, and the other listener will not get triggered every time one of the files is finished playing.

Expected result

onMediaItemTransition to be triggered every time a file finishes playing.

Actual result

onMediaItemTransition is not triggered every time a file finishes playing.

Media

I will have to wait until I can access the files to post them.

Bug Report

The listener is not triggered when the same file plays twice in a row.

My bad. This is a duplicate of #68

This fixed it

    private var mediaItem: MediaItem? = null

    override fun onPositionDiscontinuity(
        oldPosition: Player.PositionInfo,
        newPosition: Player.PositionInfo,
        reason: Int
    ) {
        super.onPositionDiscontinuity(oldPosition, newPosition, reason)
        if(reason == DISCONTINUITY_REASON_AUTO_TRANSITION){
            val id = mediaItem?.mediaId?.toLong()
            id?.let {
                observedCounts[id] = (observedCounts[id] ?: 0L) + 1
                countDownLatch.countDown()
            }
        }
    }

    override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) {
        super.onMediaItemTransition(mediaItem, reason)
        if (reason == MEDIA_ITEM_TRANSITION_REASON_AUTO) {
            this.mediaItem = mediaItem
        }
    }