Skip to content

Audio files less than 1 second do not always trigger onMediaItemTransition #1458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
aljohnston112 opened this issue Jun 13, 2024 · 2 comments
Closed
1 task done

Comments

@aljohnston112
Copy link

aljohnston112 commented Jun 13, 2024

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

@aljohnston112
Copy link
Author

aljohnston112 commented Jun 13, 2024

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

@aljohnston112
Copy link
Author

aljohnston112 commented Jun 13, 2024

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
        }
    }

@aljohnston112 aljohnston112 reopened this Jun 13, 2024
@androidx androidx locked and limited conversation to collaborators Aug 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant