diff options
author | cmp <camporter1@gmail.com> | 2023-03-11 04:48:02 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-11 04:48:02 +0000 |
commit | 34cb71f7079fee897e53f43acb499f37df71f99e (patch) | |
tree | 329e212fac22c61fbb4d4ff18851fdca5dfd8395 /app/src/main/java/ml | |
parent | 9a1046eda20151d6b4df519a57cdcb7055d8e1ca (diff) | |
download | infinity-for-reddit-34cb71f7079fee897e53f43acb499f37df71f99e.tar infinity-for-reddit-34cb71f7079fee897e53f43acb499f37df71f99e.tar.gz infinity-for-reddit-34cb71f7079fee897e53f43acb499f37df71f99e.tar.bz2 infinity-for-reddit-34cb71f7079fee897e53f43acb499f37df71f99e.tar.lz infinity-for-reddit-34cb71f7079fee897e53f43acb499f37df71f99e.tar.xz infinity-for-reddit-34cb71f7079fee897e53f43acb499f37df71f99e.tar.zst infinity-for-reddit-34cb71f7079fee897e53f43acb499f37df71f99e.zip |
For v.reddit HLS, try to prefer the stereo audio track. (#1376)
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java index ae8de478..07840a95 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java @@ -55,6 +55,7 @@ import com.google.android.exoplayer2.Tracks; import com.google.android.exoplayer2.source.ProgressiveMediaSource; import com.google.android.exoplayer2.source.hls.HlsMediaSource; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; +import com.google.android.exoplayer2.trackselection.TrackSelectionOverride; import com.google.android.exoplayer2.ui.PlayerControlView; import com.google.android.exoplayer2.ui.TrackSelectionDialogBuilder; import com.google.android.exoplayer2.upstream.DataSource; @@ -637,22 +638,35 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe }); } - for (int i = 0; i < trackGroups.size(); i++) { - String mimeType = trackGroups.get(i).getTrackFormat(0).sampleMimeType; - if (mimeType != null && mimeType.contains("audio")) { - muteButton.setVisibility(View.VISIBLE); - muteButton.setOnClickListener(view -> { - if (isMute) { - isMute = false; - player.setVolume(1f); - muteButton.setImageResource(R.drawable.ic_unmute_24dp); - } else { - isMute = true; - player.setVolume(0f); - muteButton.setImageResource(R.drawable.ic_mute_24dp); - } - }); - break; + for (Tracks.Group trackGroup : tracks.getGroups()) { + if (trackGroup.getType() == C.TRACK_TYPE_AUDIO) { + if (videoType == VIDEO_TYPE_NORMAL && trackGroup.length > 1) { + // Reddit video HLS usually has two audio tracks. The first is mono. + // The second (index 1) is stereo. + // Select the stereo audio track if possible. + trackSelector.setParameters( + trackSelector.buildUponParameters() + .setOverrideForType(new TrackSelectionOverride( + trackGroup.getMediaTrackGroup(), + 1 + ) + ) + ); + } + if (muteButton.getVisibility() != View.VISIBLE) { + muteButton.setVisibility(View.VISIBLE); + muteButton.setOnClickListener(view -> { + if (isMute) { + isMute = false; + player.setVolume(1f); + muteButton.setImageResource(R.drawable.ic_unmute_24dp); + } else { + isMute = true; + player.setVolume(0f); + muteButton.setImageResource(R.drawable.ic_mute_24dp); + } + }); + } } } } else { |