1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-11-05 09:36:22 +00:00

feat: add external audio playback language selector

This commit is contained in:
ThetaDev 2023-03-19 21:05:48 +01:00
parent 7aed2eed8a
commit ef0a4cf8b2
3 changed files with 52 additions and 22 deletions

View File

@ -164,8 +164,12 @@ public final class VideoDetailFragment
private boolean showRelatedItems;
private boolean showDescription;
private String selectedTabTag;
@AttrRes @NonNull final List<Integer> tabIcons = new ArrayList<>();
@StringRes @NonNull final List<Integer> tabContentDescriptions = new ArrayList<>();
@AttrRes
@NonNull
final List<Integer> tabIcons = new ArrayList<>();
@StringRes
@NonNull
final List<Integer> tabContentDescriptions = new ArrayList<>();
private boolean tabSettingsChanged = false;
private int lastAppBarVerticalOffset = Integer.MAX_VALUE; // prevents useless updates
@ -1042,20 +1046,10 @@ public final class VideoDetailFragment
player.setRecovery();
}
if (!useExternalAudioPlayer) {
openNormalBackgroundPlayer(append);
if (useExternalAudioPlayer) {
showExternalAudioPlaybackDialog();
} else {
final List<AudioStream> audioStreams = getUrlAndNonTorrentStreams(
currentInfo.getAudioStreams());
final int index = ListHelper.getDefaultAudioFormat(activity, audioStreams);
if (index == -1) {
Toast.makeText(activity, R.string.no_audio_streams_available_for_external_players,
Toast.LENGTH_SHORT).show();
return;
}
startOnExternalPlayer(activity, currentInfo, audioStreams.get(index));
openNormalBackgroundPlayer(append);
}
}
@ -1108,7 +1102,7 @@ public final class VideoDetailFragment
if (PreferenceManager.getDefaultSharedPreferences(activity)
.getBoolean(this.getString(R.string.use_external_video_player_key), false)) {
showExternalPlaybackDialog();
showExternalVideoPlaybackDialog();
} else {
replaceQueueIfUserConfirms(this::openMainPlayer);
}
@ -2102,7 +2096,7 @@ public final class VideoDetailFragment
}).show();
}
private void showExternalPlaybackDialog() {
private void showExternalVideoPlaybackDialog() {
if (currentInfo == null) {
return;
}
@ -2149,6 +2143,43 @@ public final class VideoDetailFragment
builder.show();
}
private void showExternalAudioPlaybackDialog() {
if (currentInfo == null) {
return;
}
final List<AudioStream> audioStreams = getUrlAndNonTorrentStreams(
currentInfo.getAudioStreams());
final List<AudioStream> audioTracks =
ListHelper.getFilteredAudioStreams(activity, audioStreams);
if (audioTracks.isEmpty()) {
Toast.makeText(activity, R.string.no_audio_streams_available_for_external_players,
Toast.LENGTH_SHORT).show();
} else if (audioTracks.size() == 1) {
startOnExternalPlayer(activity, currentInfo, audioTracks.get(0));
} else {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.select_audio_track_external_players);
final int selectedAudioStream =
ListHelper.getDefaultAudioFormat(activity, audioTracks);
final CharSequence[] trackNames = audioTracks.stream()
.map(audioStream -> Localization.audioTrackName(activity, audioStream))
.toArray(CharSequence[]::new);
builder.setSingleChoiceItems(trackNames, selectedAudioStream, null);
builder.setNegativeButton(R.string.cancel, null);
builder.setPositiveButton(R.string.ok, (dialog, i) -> {
final int index = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
startOnExternalPlayer(activity, currentInfo,
audioTracks.get(index));
});
builder.show();
}
}
/*
* Remove unneeded information while waiting for a next task
* */

View File

@ -5,7 +5,6 @@ import static org.schabi.newpipe.player.helper.PlayerHelper.formatSpeed;
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
@ -618,7 +617,6 @@ public final class PlayQueueActivity extends AppCompatActivity
return;
}
final Context context = player.getContext();
final MenuItem audioTrackSelector = menu.findItem(R.id.action_audio_track);
final List<AudioStream> availableStreams =
Optional.ofNullable(player.getCurrentMetadata())
@ -637,13 +635,13 @@ public final class PlayQueueActivity extends AppCompatActivity
for (int i = 0; i < availableStreams.size(); i++) {
final AudioStream audioStream = availableStreams.get(i);
audioTrackMenu.add(MENU_ID_AUDIO_TRACK, i, Menu.NONE,
Localization.audioTrackName(context, audioStream));
Localization.audioTrackName(this, audioStream));
}
final AudioStream s = selectedAudioStream.get();
final String trackName = Localization.audioTrackName(context, s);
final String trackName = Localization.audioTrackName(this, s);
audioTrackSelector.setTitle(
context.getString(R.string.play_queue_audio_track, trackName));
getString(R.string.play_queue_audio_track, trackName));
final String shortName = s.getAudioLocale() != null
? s.getAudioLocale().getLanguage() : trackName;

View File

@ -768,6 +768,7 @@
<string name="no_audio_streams_available_for_external_players">No audio streams are available for external players</string>
<string name="no_video_streams_available_for_external_players">No video streams are available for external players</string>
<string name="select_quality_external_players">Select quality for external players</string>
<string name="select_audio_track_external_players">Select audio track for external players</string>
<string name="unknown_format">Unknown format</string>
<string name="unknown_quality">Unknown quality</string>
<string name="unknown_audio_track">Unknown</string>