Skip to content

Instantly share code, notes, and snippets.

@abhiint16
Created June 3, 2019 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save abhiint16/165449a1a7d1a55a8f69d23718c603c2 to your computer and use it in GitHub Desktop.
Save abhiint16/165449a1a7d1a55a8f69d23718c603c2 to your computer and use it in GitHub Desktop.
track_selection_text.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
if (mappedTrackInfo != null) {
//CharSequence title = ((Button) view).getText();
//int rendererIndex = (int) v.getTag();
int rendererType = mappedTrackInfo.getRendererType(0);
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, TrackSelection> dialogPair = TrackSelection
.getDialog(activity, "Video", trackSelector, 0, VideoPlayer.this,
track_selection_text.getText().toString(), player.getVideoFormat());
dialogPair.second.setShowDisableOption(false);
dialogPair.second.setAllowAdaptiveSelections(allowAdaptiveSelections);
dialogPair.first.show();
}
}
});
@dubariyaankit
Copy link

i got below error

 java.lang.ClassCastException: com.google.android.exoplayer2.ui.TrackSelectionView cannot be cast to com.maxtv.activity.tv.TrackSelection
        at com.maxtv.activity.tv.TrackSelection.getDialog(TrackSelection.java:61)
        at com.maxtv.activity.tv.NewPlayerActivity.showQualityPopUp(NewPlayerActivity.java:195)

in this line

TrackSelector.java
final TrackSelection selectionView = dialogView.findViewById(R.id.exo_track_selection_view);

@dubariyaankit
Copy link

this is my code

DefaultTrackSelector trackSelector = ExoPlayerManager.getSharedInstance(NewPlayerActivity.this).getTrackSelector();
        MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
        if (mappedTrackInfo != null) {
            //CharSequence title = ((Button) view).getText();
            //int rendererIndex = (int) v.getTag();
            int rendererType = mappedTrackInfo.getRendererType(0);
            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, TrackSelection> dialogPair = TrackSelection
                    .getDialog(this, "Video", trackSelector, 0, NewPlayerActivity.this,
                            "");
            dialogPair.second.setShowDisableOption(false);
            dialogPair.second.setAllowAdaptiveSelections(allowAdaptiveSelections);
            dialogPair.first.show();
        }

i don't able to pass player.getVideoFormat() in below line

Pair<AlertDialog, TrackSelection> dialogPair = TrackSelection
                    .getDialog(this, "Video", trackSelector, 0, NewPlayerActivity.this,
                            "", HERE);

@abhiint16
Copy link
Author

You'll have to open "exo_track_selection_view" XML and then change the package name (path name)to your custom TrackSelector.java
you'll find something like below in the XML

`

<X.Y.Z.TrackSelection
    android:id="@+id/exo_track_selection_init_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" />

`

you need to change X.Y.Z.Trackselection to com.maxtv.activity.tv.TrackSelection

@abhiint16
Copy link
Author

For your second issue that is, player.getVideoFormat(), just do one thing, replace the TrackSelection.java with the updated TrackSelection.java here https://gist.github.com/abhiint16/b473e9b1111bd8bda4833c288ae6a1b4

@langaliamayank
Copy link

Pair<AlertDialog, NewTrackSelection> dialogPair = NewTrackSelection
                        .getDialog(PlayerActivity.this, "Video", trackSelector, 0, **PlayerActivity.this,**
                                "L", mPlayer.getVideoFormat());

I Got error GetReso field what should i write here? We need to pass activity.this or anything else ?
PlayerActivity.this,

@abhiint16
Copy link
Author

@MayankSoni

If you see the above code of mine, VideoPayer is the class in which I have written this code in and I have also implemented GetReso interface in VideoPlayer, So if you're passing PlayerActivity.this, GetReso interface you should implement in PlayerActivity class.

@fridapinto-debug
Copy link

fridapinto-debug commented Apr 15, 2020

can you share your Playeractivity class could not understand that getReso part. @abhiint16

@abhiint16
Copy link
Author

abhiint16 commented Sep 30, 2020

@fridapinto-debug

GetReso is just an Interface. Check line no. 50s in this - https://gist.github.com/abhiint16/b473e9b1111bd8bda4833c288ae6a1b4

So, you can implement this interface in your PlayerActivity and hence you'll get a callback method
void getResoText(String resoText);

Now, this callback method will be called with the string value (Low, Med, High etc) whenever you change your resolution in TrackSelection.

@langaliamayank
Copy link


Untitled

Please check my attachment image. getResoText(getResoText) Added but not understand how to set? could you please help me ?

@langaliamayank
Copy link

@fridapinto-debug

getReso is just an Interface. Check line no. 50s in this - https://gist.github.com/abhiint16/b473e9b1111bd8bda4833c288ae6a1b4

So, you can implement this interface in your PlayerActivity and hence you'll get a callback method
void getResoText(String resoText);

Now, this callback method will be called with the string value (Low, Med, High etc) whenever you change your resolution in TrackSelection.

This is understand but Pair<AlertDialog, MyTrackSelection> dialogPair = MyTrackSelection
.getDialog(PlayerActivity.this, "Video Qualiry", mTrackSelector, 0,
getResoText(getResoText), mTrackSelector.toString(), mPlayer.getVideoFormat()); Pls check my sample. Let me know how to solved this

@abhiint16
Copy link
Author

@langaliamayank

  1. You need to implement GetReso interface
  2. Then, override the provided method from GetReso interface.

then,

Pair<AlertDialog, MyTrackSelection> dialogPair = MyTrackSelection.getDialog(context, "Video Quality", mTrackSelector, 0, this, track_selection_text.getText().toString())

@langaliamayank
Copy link

override the provided method from GetReso interface.
what should i write in this method?

@langaliamayank
Copy link

Screenshot (55)

Inside dialog nothing to show.

@abhiint16
Copy link
Author

@langaliamayank

Each video that you play has to provide resolution list to show it to your user. You need to debug in MyTackSelection's updateViews() method and see for trackGroups.length. For you, it seems that the length is 0

@langaliamayank
Copy link

override the provided method from GetReso interface.
what should i write in this method?

@langaliamayank
Copy link

Can you please elaborate what should i do ? Because if its normal list then its working fine,,,,

@abhiint16
Copy link
Author

abhiint16 commented Oct 30, 2020 via email

@langaliamayank
Copy link

Could you please share me some sample code ?
The overridden method is used show the selected resolution to the UI.

@langaliamayank
Copy link

@langaliamayank

Each video that you play has to provide resolution list to show it to your user. You need to debug in MyTackSelection's updateViews() method and see for trackGroups.length. For you, it seems that the length is 0

Track length getting 1.

@AnuragRastogi1
Copy link

You'll have to open "exo_track_selection_view" XML and then change the package name (path name)to your custom TrackSelector.java
you'll find something like below in the XML

`

<X.Y.Z.TrackSelection
    android:id="@+id/exo_track_selection_init_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" />

`

you need to change X.Y.Z.Trackselection to com.maxtv.activity.tv.TrackSelection

So if i am doing this , i am not able to set my player

@avimone
Copy link

avimone commented Jun 4, 2021

how to open exo_track_selection_dialog.xml and change to TrackSelection.
im getting this error
java.lang.ClassCastException: androidx.viewpager.widget.ViewPager cannot be cast to co.appmastery.worldbbtv.downloader.TrackSelection E/AndroidRuntime(30347): at co.appmastery.worldbbtv.downloader.TrackSelection.getDialog(TrackSelection.java:70) E/AndroidRuntime(30347): at co.appmastery.worldbbtv.PlayerActivity.test(PlayerActivity.java:909)

@Allan-Nava
Copy link

Any fix with the resoultion like youtube only 720 , 360 etc?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment