ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

How can I overwrite the video TrackGroup in the TrackGroupArray

Open userdimi opened this issue 7 years ago • 3 comments

[REQUIRED] Searched documentation and issues

Exoplayer Github project Exoplayer Docs

[REQUIRED] Question

In my video streaming app I want to implement a feature where the user can choose the streaming quality for the video. So I've implemented this with a TrackSelectionView like this:

public void showQualitySettingsDialog(Activity activity) {
		overrideVideoTrackGroup(trackSelector);
		MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
		if (mappedTrackInfo != null) {
			int rendererIndex = getVideoRendererIndex(trackSelector);
			Pair<AlertDialog, TrackSelectionView> dialogPair =
				TrackSelectionView.getDialog(activity, activity.getString(R.string.video_quality), trackSelector, rendererIndex);
			dialogPair.first.show();
		}
	}

	private int getVideoRendererIndex(DefaultTrackSelector trackSelector) {
		int videoRendererIndex = 0;
		MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
		if (mappedTrackInfo != null) {
			for (int i = 0; i < mappedTrackInfo.getRendererCount(); i++) {
				TrackGroupArray trackGroups = mappedTrackInfo.getTrackGroups(i);
				if (trackGroups.length != 0 && player.getRendererType(i) == C.TRACK_TYPE_VIDEO) {
					videoRendererIndex = i;
				}
			}
		}
		return videoRendererIndex;
	}

This work pretty good. But the problem is, that I have some duplicated video tracks in my HLS master file (look at the test content). So I wrote a method to sort the TrackGroup for the video like this

private TrackGroup getSortedVideoTrackGroup(@NonNull ArrayList<Format> formatList) {
		Format [] formats = new Format[formatList.size()];
		for (int i = 0; i < formatList.size(); i++) {
			formats[i] = formatList.get(i);
		}
		return new TrackGroup(formats);
	}

	private ArrayList<Format> getSortedFormatArrayList(DefaultTrackSelector trackSelector)  {
		ArrayList<Format> formatArrayList = new ArrayList<>();
		Format tempFormat = null;
		MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
		if (mappedTrackInfo != null) {
			for (int trackGroups = 0; trackGroups < mappedTrackInfo.getRendererCount(); trackGroups++) {
				TrackGroupArray trackGroupArray = mappedTrackInfo.getTrackGroups(trackGroups);
				if (trackGroupArray.length != 0 && player.getRendererType(trackGroups) == C.TRACK_TYPE_VIDEO) {
					//Trackgroup Array für videos auslesen
					for (int j = 0; j < trackGroupArray.length; j++) {
						TrackGroup trackGroup = trackGroupArray.get(j);
						for (int k = 0; k < trackGroup.length; k++) {
							Format format = trackGroup.getFormat(k);
							if (tempFormat == null) {
								tempFormat = format;
							} else {
								if (tempFormat.bitrate != format.bitrate) {
									formatArrayList.add(format);
									tempFormat = format;
								}
							}
						}
					}
				}
			}
		}
		return formatArrayList;
	}

So far so good. Now my question is, how can I overwrite the video TrackGroup in the TrackGroupArray with the "sorted" TrackGroup to prevent to display video tracks double.

You can reproduce my issue with the exoplayer demo app.

Link to test content

http://zdf1314-lh.akamaihd.net/i/de14_v1@392878/master.m3u8

A full bug report captured from the device

not required

userdimi avatar Jun 22 '19 16:06 userdimi

This issue does not have all the information required by the template. Looks like you forgot to fill out some sections. Please update the issue with more information.

google-oss-bot avatar Jun 22 '19 16:06 google-oss-bot

You may consider giving controls like - Low (SD), Medium (HD), High (Full-HD). Exoplayer Track Selector will limit the quality. Use setMaxVideoSize(), setMaxVideoBitrate() etc. in DefaultTrackSelector to control the same.

You will not have to filter available tracks, or remove fallback tracks etc.

umangsaini avatar Jun 24 '19 14:06 umangsaini

Now my question is, how can I overwrite the video TrackGroup in the TrackGroupArray with the "sorted" TrackGroup to prevent to display video tracks double.

I don't really understand the question. You can and should do all sorting/filtering in your UI layer, which is under your control.

ojw28 avatar Jun 24 '19 14:06 ojw28