2

I am using Exoplayer version 2.7.2, and I want to iterate over MappedTrackInfo to get all the available TrackGroupArray of a DASH video. But DefaultTrackSelector#getCurrentMappedTrackInfo is returning null.

Here's my code:

PlayerTrackSelector.kt:

class PlayerTrackSelector : TrackSelection.Factory {

    override fun createTrackSelection(
        group: TrackGroup?,
        bandwidthMeter: BandwidthMeter?,
        vararg tracks: Int
    ): TrackSelection {

        return AdaptiveTrackSelection(
            group!!, tracks,bandwidthMeter,
            AdaptiveTrackSelection.DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS.toLong(),
            AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS.toLong(),
            AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS.toLong(),
            AdaptiveTrackSelection.DEFAULT_BANDWIDTH_FRACTION,
            AdaptiveTrackSelection.DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
            AdaptiveTrackSelection.DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
            Clock.DEFAULT
        )
    }
}

MainActivity.kt

 logTracks(DefualtTrackSelector(PlayerTrackSelector())) // This is called after Player#prepare

 private fun logTracks(trackSelector: DefaultTrackSelector?) {
    var trackGroupArray: TrackGroupArray? = null

    val mappedTrackInfo = trackSelector!!.currentMappedTrackInfo

        if(mappedTrackInfo != null) {
            if (mappedTrackInfo!!.rendererCount != 0) {
                for (i in 0 until mappedTrackInfo.rendererCount) {
                    if (mappedTrackInfo.getTrackGroups(i) != null) {
                        val tempTrackGroupArray = mappedTrackInfo.getTrackGroups(i)
                        if (tempTrackGroupArray.length != 0 && player!!.getRendererType(i) == C.TRACK_TYPE_VIDEO) {
                            trackGroupArray = tempTrackGroupArray
                        }
                    } else {
                        Log.d(TAG, "Null, MappedTrackInfo#getTrackGroups(index)")
                    }
                }

                for (i in 0 until trackGroupArray!!.length) {
                    val trackGroup = trackGroupArray.get(i)
                    for (j in 0 until trackGroup.length) {
                        val format = trackGroup.getFormat(j)
                        Log.d(TAG,"Height = ${format.height} GroupIndex = $i TrackIndex = $j")
                    }
                }
            } else {
                Log.d(TAG, "Empty, MappedTrackInfo#renderCount")
            }
        }else{
            Log.d(TAG, "Null, MappedTrackInfo") //This is what shows in logcat.
        }
}

I have tried with different MPDs aswell.

Info:

1) Dependencies:

implementation 'com.google.android.exoplayer:exoplayer:2.7.2'
implementation 'com.google.android.exoplayer:exoplayer-core:2.10.5'
implementation 'com.google.android.exoplayer:exoplayer-dash:2.10.5'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.10.5'

2) URL : https://s3.amazonaws.com/_bc_dml/example-content/sintel_dash/sintel_vod.mpd

God Shashank
  • 21
  • 1
  • 2
  • Look at my updated answer ;) – Biscuit Sep 27 '20 at 15:57
  • It may be the case that the player may not be ready by the time you're calling `getCurrentMappedTrackInfo()`. For instance, making the call on onClick of a button in the player worked for me. – h8pathak Oct 31 '20 at 06:24

1 Answers1

-1

You need to add the Player.EventListener and wait for the playbackState to be at Player.STATE_READY

private val eventListener: Player.EventListener = object : Player.EventListener {
        override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {
            if (playbackState == Player.STATE_READY) {
                // look for MappedTrackInfo
            }
        }
Biscuit
  • 4,840
  • 4
  • 26
  • 54