I am working with an app that is supposed to play YouTube videos using ExoPlayer2. To fetch the DASH URL of the video I am using this library. The problem with this approach is that the library returns different URLs based on what resolution (itag) you want. For example, if you want the 720p variant of a video you will do something like:
String youtubeLink = "http://youtube.com/watch?v=xxxx";
new YouTubeExtractor(this) {
@Override
public void onExtractionComplete(SparseArray<YtFile> ytFiles, VideoMeta vMeta) {
if (ytFiles != null) {
int itag = 22; //22 == 720p
String downloadUrl = ytFiles.get(itag).getUrl();
}
}
}.extract(youtubeLink, true, true);
I can make this URL as a MediaSource and set it using setMediaSource
and it works but with only a single resolution (720p in this case). I want to do something like the photo attached to the answer to this question.
I tried reading the docs, I tried Google-Fu but all went in vain. Any ideas on how can I create different tracks with different resolutions for the same video? I tried putting MediaItem
s and setting them to the player but it instead creates a playlist rather than tracks. Any help?
Sorry for the lack of code, the previous developer has made a complete mess in organizing the code and I do not know what is where. If I can just get a rough code that would be insanely helpful.
Thanks