android – Customizing exoplayer quality dialog in my app-ThrowExceptions

Exception or error:

I have video player in my android app and I make them using exoplayer library. My player can to play .m3u8 videos (I obtain them from backend) and all of them can be in different quality, for example, 1024×576, 768×432, etc. I want to show for user dialog with possibility to change video stream quality. For this i use the next code from exoplayer samples in github:

MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
        if (mappedTrackInfo != null) {
            CharSequence title = "Tit;eee";
            int rendererIndex = 0; // renderer for video
            int rendererType = mappedTrackInfo.getRendererType(rendererIndex);
            boolean allowAdaptiveSelections =
                    rendererType == C.TRACK_TYPE_VIDEO
                            || (rendererType == C.TRACK_TYPE_AUDIO
                            && mappedTrackInfo.getTypeSupport(C.TRACK_TYPE_VIDEO)
                            == MappingTrackSelector.MappedTrackInfo.RENDERER_SUPPORT_NO_TRACKS);


            Pair<AlertDialog, TrackSelectionView> dialogPair =
                    TrackSelectionView.getDialog(this, title, trackSelector, rendererIndex);
            dialogPair.second.setShowDisableOption(true);
            dialogPair.second.setAllowAdaptiveSelections(allowAdaptiveSelections);
            dialogPair.first.show();
}

and it works okay. But, i need to customize this dialog, for example deleting “none” option and making ALL elements single choice only. How can I make this?

How to solve:

This might be late but here are the ways to do so,

Here the main Class that does all these awesome stuff is “TrackSelectionView”, this class simply extends a LinearLayout. To achieve your desired features you need to make your own class (name is anything) and then just copy paste the entire code of TrackSelectionView in it. Why are we doing so? coz, we need to change some logic of that class and it’s a read-only class.

Actually to achieve the first feature (no “none” option) you simply can write dialogPair.second.setShowDisableOption(false); instead of that “true”.

Writing our own class and copy-paste code is for the second feature.

In “TrackSelectionView” it uses a 2-D array to store the CheckedTextView. For the first two togglebuttons (Auto and None) it uses CheckedTextView separately but for all other resolution, CheckedTextView is getting stored in that 2-D array.

I won’t post the entire codebase here as it will make things messy, I have created a github.gist file, you can get a reference from there…

https://gist.github.com/abhiint16/b473e9b1111bd8bda4833c288ae6a1b4

Don’t forget to use your class reference instead of TrackSelectionView.

You will use this above file as shown in this Gist
https://gist.github.com/abhiint16/165449a1a7d1a55a8f69d23718c603c2

The Gist file makes the selection “Single-select” and in addition to that it also performs an awesome stuff for you in case you need it in your ExoPlayer,

enter image description here

Here, the actual video format that you get is in 512 X 288, 0.57 Mbps format in a list, I’m just mapping predefined Low, Medium, High etc with the index of list. You can try your own way.

So when you click on one of the resolution, it transforms the textview of your exoplayer for the selected-resolution (“L” for “Low”).

For that you just need to implement an Interface named GetReso in your Class and there you’ll get the selected text-initial. Now you can just set that string to a textview.

enter image description here

Enjoy coding…..

Leave a Reply

Your email address will not be published. Required fields are marked *