Skip to content

HLS MaxAudioBitrate limit not working #6006

@jakoss

Description

@jakoss

Content description

I'm trying to stream audio only files (AAC and MP3, both codecs have the same issue). I generated 3 different bitrates playlists (256k, 192k and 128k) and then master playlist.
I need to be able to limit max bitrate (if users want to limit their data usage) to set values. So i have code:

private val exoPlayer: SimpleExoPlayer by lazy {
        val adaptiveTrackSelection = AdaptiveTrackSelection.Factory()
        val trackSelector = DefaultTrackSelector(adaptiveTrackSelection)
        trackSelector.setParameters(DefaultTrackSelector.ParametersBuilder()
// here i'm trying to force lowest bitrate for testing purposes
            .setMaxAudioBitrate(128_000)
            .setExceedAudioConstraintsIfNecessary(false)
            .setForceLowestBitrate(true))

        ExoPlayerFactory.newSimpleInstance(this, trackSelector).apply {
            setAudioAttributes(uAmpAudioAttributes, true)
            addAnalyticsListener(EventLogger(trackSelector))
            val debugViewHelper = DebugTextViewHelper(this, debug_text_view)
            debugViewHelper.start()
        }
    }

And i setup hls media source like that (just static test streams):

private fun createMediaSource(): MediaSource {
        val dataSourceFactory = DefaultDataSourceFactory(this, "ExoPlayer")
        val hlsMediaSourceFactory = HlsMediaSource.Factory(dataSourceFactory)
            .setAllowChunklessPreparation(true)
        val track1 = hlsMediaSourceFactory.createMediaSource(Uri.parse("http://10.0.2.2:5000/streams/despacito/master.m3u8"))
        val track2 = hlsMediaSourceFactory.createMediaSource(Uri.parse("http://10.0.2.2:5000/streams/duality/master.m3u8"))
        val track3 = hlsMediaSourceFactory.createMediaSource(Uri.parse("http://10.0.2.2:5000/streams/blackorwhite/master.m3u8"))

        return ConcatenatingMediaSource(track1, track2, track3)
    }

It's playing very well, no issues here, but unfortunetely, with this setup, exoplayer always chooses track with highest bitrate. Logs:

D/EventLogger: tracksChanged [26.35, 0.00, window=1, period=1, 
      Renderer:1 [
        Group:0, adaptive_supported=YES_NOT_SEAMLESS [
          [ ] Track:0, id=0, mimeType=audio/mp4a-latm, bitrate=281600, codecs=mp4a.40.2, supported=YES
          [ ] Track:1, id=1, mimeType=audio/mp4a-latm, bitrate=211200, codecs=mp4a.40.2, supported=YES
          [ ] Track:2, id=2, mimeType=audio/mp4a-latm, bitrate=140800, codecs=mp4a.40.2, supported=YES
        ]
      ]
      Renderer:3 [
        Group:0, adaptive_supported=N/A [
          [X] Track:0, id=ID3, mimeType=application/id3, supported=YES
        ]
      ]
    ]

I found configuring adaptive streaming very confusing, since internet is full of samples with old api versions and i wasn't able to find some official documentation about that.

Link to test content

Whole streamed content: files.zip

Version of ExoPlayer being used

2.10.1

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

Mutiple versions of android on Android Emulator and on physical device (Nokia 8)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions