Skip to content

Problem with codec re-initialization during HLS MP3 playback #5063

@Curwer-zz

Description

@Curwer-zz

Issue description

We use exoPlayer for audio playback, but we have a problem with where the audio codec gets released and just milliseconds later it initialized again. This creates a short but noticed "cut" in the audio. When looking in profiler we can tell that something is happening. i´ll attach a link to a screenshot of the profiler output.
This is what it looks like when we init the player ..

if (bookChanged || exoPlayer == null) {
            release(false)

            if (exoPlayer == null) {
                exoPlayer = ExoPlayerFactory.newSimpleInstance(context, DefaultTrackSelector(AdaptiveTrackSelection.Factory(DefaultBandwidthMeter())))
                exoPlayer?.addListener(exoPlayerEventListener)
            }

//            exoPlayer?.audioStreamType = AudioManager.STREAM_VOICE_CALL
            exoPlayer?.audioAttributes = AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_SONIFICATION).setUsage(C.USAGE_MEDIA).build()
            exoPlayer?.playWhenReady = playWhenReady
            // exoPlayer?.playbackParameters = PlaybackParameters(speed, 1f) // Not working if set here. Set in onLoadingChanged() instead
            playOnFocusGain = playWhenReady

            if (position != null && position > 0) seekToPositionOnPlay = position * 1000L

            exoPlayer?.prepare(getMediaSource(book)) // Triggers onPlayerStateChanged when the stream is ready to play

            if (seekToPositionOnPlay != null) {
                exoPlayer?.seekTo(seekToPositionOnPlay!!)
                seekToPositionOnPlay = null
            } else {
                exoPlayer?.seekTo(0)
            }

            callback?.onPlaybackStatusChanged(state)

            wifiLock.acquire()
        }
`

private fun getMediaSource(book: Book): MediaSource {
        return if (offlineHelper.getCachedBooks.contains(book.isbn)) {
            val file = File(FileUtils.getDirectory(context.filesDir, FileUtils.OFFLINE_MP3), "${book.isbn}.mp3")
            Timber.e("playing mp3")
            ExtractorMediaSource
                    .Factory(DefaultDataSourceFactory(context, userAgent, null))
                    .createMediaSource(Uri.parse(file.toString()))
        } else {
            Timber.e("playing HLS")
            HlsMediaSource
                    .Factory(HlsDataSourceFactory { offlineHelper.dataSourceFactory?.createDataSource() })
                    .setPlaylistParser { uri, inputStream ->
                        val playlist = HlsPlaylistParser().parse(uri, inputStream)
                        playlist
                    }
                    .createMediaSource(Uri.parse(book.streamUrl))
        }

Reproduction steps

You can try with this link right here.
http://delivery-42-lb1.elib.se/library/v4/mp3:http/2f0d8302-ca3f-4f8c-9c89-1f18c4e1df06.mp3/playlist.m3u8?StreamSession=79cb6038-9a03-467c-9193-a6a466f547c2&validate=3ca0f7b4436f43b5c99006788f0629cf

For us it´s enough just to play the stream, this happens on both our app, and the a different app that the company providing the links wrote, also based on exoPlayer.

Link to test content

http://delivery-42-lb1.elib.se/library/v4/mp3:http/2f0d8302-ca3f-4f8c-9c89-1f18c4e1df06.mp3/playlist.m3u8?StreamSession=79cb6038-9a03-467c-9193-a6a466f547c2&validate=3ca0f7b4436f43b5c99006788f0629cf

Version of ExoPlayer being used

2.7.0 (also tried to bump to 2.9.0 with no luck)

Device(s) and version(s) of Android being used

Samsung galaxy s8+ / s7 both running 8.0.0
Huawei Honor 8 android 7.0
Google Pixel 2XL runnig 9.0.0

A full bug report captured from the device

I have sent you a mail with the profile trace session we captured.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions