mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-01-03 14:00:32 +00:00
feat: add external audio playback language selector
This commit is contained in:
parent
7aed2eed8a
commit
ef0a4cf8b2
@ -164,8 +164,12 @@ public final class VideoDetailFragment
|
|||||||
private boolean showRelatedItems;
|
private boolean showRelatedItems;
|
||||||
private boolean showDescription;
|
private boolean showDescription;
|
||||||
private String selectedTabTag;
|
private String selectedTabTag;
|
||||||
@AttrRes @NonNull final List<Integer> tabIcons = new ArrayList<>();
|
@AttrRes
|
||||||
@StringRes @NonNull final List<Integer> tabContentDescriptions = new ArrayList<>();
|
@NonNull
|
||||||
|
final List<Integer> tabIcons = new ArrayList<>();
|
||||||
|
@StringRes
|
||||||
|
@NonNull
|
||||||
|
final List<Integer> tabContentDescriptions = new ArrayList<>();
|
||||||
private boolean tabSettingsChanged = false;
|
private boolean tabSettingsChanged = false;
|
||||||
private int lastAppBarVerticalOffset = Integer.MAX_VALUE; // prevents useless updates
|
private int lastAppBarVerticalOffset = Integer.MAX_VALUE; // prevents useless updates
|
||||||
|
|
||||||
@ -1042,20 +1046,10 @@ public final class VideoDetailFragment
|
|||||||
player.setRecovery();
|
player.setRecovery();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!useExternalAudioPlayer) {
|
if (useExternalAudioPlayer) {
|
||||||
openNormalBackgroundPlayer(append);
|
showExternalAudioPlaybackDialog();
|
||||||
} else {
|
} else {
|
||||||
final List<AudioStream> audioStreams = getUrlAndNonTorrentStreams(
|
openNormalBackgroundPlayer(append);
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1108,7 +1102,7 @@ public final class VideoDetailFragment
|
|||||||
|
|
||||||
if (PreferenceManager.getDefaultSharedPreferences(activity)
|
if (PreferenceManager.getDefaultSharedPreferences(activity)
|
||||||
.getBoolean(this.getString(R.string.use_external_video_player_key), false)) {
|
.getBoolean(this.getString(R.string.use_external_video_player_key), false)) {
|
||||||
showExternalPlaybackDialog();
|
showExternalVideoPlaybackDialog();
|
||||||
} else {
|
} else {
|
||||||
replaceQueueIfUserConfirms(this::openMainPlayer);
|
replaceQueueIfUserConfirms(this::openMainPlayer);
|
||||||
}
|
}
|
||||||
@ -2102,7 +2096,7 @@ public final class VideoDetailFragment
|
|||||||
}).show();
|
}).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showExternalPlaybackDialog() {
|
private void showExternalVideoPlaybackDialog() {
|
||||||
if (currentInfo == null) {
|
if (currentInfo == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2149,6 +2143,43 @@ public final class VideoDetailFragment
|
|||||||
builder.show();
|
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
|
* Remove unneeded information while waiting for a next task
|
||||||
* */
|
* */
|
||||||
|
@ -5,7 +5,6 @@ import static org.schabi.newpipe.player.helper.PlayerHelper.formatSpeed;
|
|||||||
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
|
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
|
||||||
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -618,7 +617,6 @@ public final class PlayQueueActivity extends AppCompatActivity
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Context context = player.getContext();
|
|
||||||
final MenuItem audioTrackSelector = menu.findItem(R.id.action_audio_track);
|
final MenuItem audioTrackSelector = menu.findItem(R.id.action_audio_track);
|
||||||
final List<AudioStream> availableStreams =
|
final List<AudioStream> availableStreams =
|
||||||
Optional.ofNullable(player.getCurrentMetadata())
|
Optional.ofNullable(player.getCurrentMetadata())
|
||||||
@ -637,13 +635,13 @@ public final class PlayQueueActivity extends AppCompatActivity
|
|||||||
for (int i = 0; i < availableStreams.size(); i++) {
|
for (int i = 0; i < availableStreams.size(); i++) {
|
||||||
final AudioStream audioStream = availableStreams.get(i);
|
final AudioStream audioStream = availableStreams.get(i);
|
||||||
audioTrackMenu.add(MENU_ID_AUDIO_TRACK, i, Menu.NONE,
|
audioTrackMenu.add(MENU_ID_AUDIO_TRACK, i, Menu.NONE,
|
||||||
Localization.audioTrackName(context, audioStream));
|
Localization.audioTrackName(this, audioStream));
|
||||||
}
|
}
|
||||||
|
|
||||||
final AudioStream s = selectedAudioStream.get();
|
final AudioStream s = selectedAudioStream.get();
|
||||||
final String trackName = Localization.audioTrackName(context, s);
|
final String trackName = Localization.audioTrackName(this, s);
|
||||||
audioTrackSelector.setTitle(
|
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
|
final String shortName = s.getAudioLocale() != null
|
||||||
? s.getAudioLocale().getLanguage() : trackName;
|
? s.getAudioLocale().getLanguage() : trackName;
|
||||||
|
@ -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_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="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_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_format">Unknown format</string>
|
||||||
<string name="unknown_quality">Unknown quality</string>
|
<string name="unknown_quality">Unknown quality</string>
|
||||||
<string name="unknown_audio_track">Unknown</string>
|
<string name="unknown_audio_track">Unknown</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user