mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-25 17:40:33 +00:00
-Fixed video player source loading for audio only streams.
-Changed "monitor leak" string to "LeakCanary" as untranslatable.
This commit is contained in:
parent
d936ca6b89
commit
e21d2bd511
@ -263,7 +263,9 @@ public abstract class VideoPlayer extends BasePlayer
|
|||||||
VideoStream videoStream = availableStreams.get(i);
|
VideoStream videoStream = availableStreams.get(i);
|
||||||
qualityPopupMenu.getMenu().add(qualityPopupMenuGroupId, i, Menu.NONE, MediaFormat.getNameById(videoStream.format) + " " + videoStream.resolution);
|
qualityPopupMenu.getMenu().add(qualityPopupMenuGroupId, i, Menu.NONE, MediaFormat.getNameById(videoStream.format) + " " + videoStream.resolution);
|
||||||
}
|
}
|
||||||
|
if (getSelectedVideoStream() != null) {
|
||||||
qualityTextView.setText(getSelectedVideoStream().resolution);
|
qualityTextView.setText(getSelectedVideoStream().resolution);
|
||||||
|
}
|
||||||
qualityPopupMenu.setOnMenuItemClickListener(this);
|
qualityPopupMenu.setOnMenuItemClickListener(this);
|
||||||
qualityPopupMenu.setOnDismissListener(this);
|
qualityPopupMenu.setOnDismissListener(this);
|
||||||
}
|
}
|
||||||
@ -326,7 +328,7 @@ public abstract class VideoPlayer extends BasePlayer
|
|||||||
qualityTextView.setVisibility(View.GONE);
|
qualityTextView.setVisibility(View.GONE);
|
||||||
playbackSpeedTextView.setVisibility(View.GONE);
|
playbackSpeedTextView.setVisibility(View.GONE);
|
||||||
|
|
||||||
if (info != null) {
|
if (info != null && info.video_streams.size() + info.video_only_streams.size() > 0) {
|
||||||
final List<VideoStream> videos = ListHelper.getSortedStreamVideosList(context,
|
final List<VideoStream> videos = ListHelper.getSortedStreamVideosList(context,
|
||||||
info.video_streams, info.video_only_streams, false);
|
info.video_streams, info.video_only_streams, false);
|
||||||
availableStreams = new ArrayList<>(videos);
|
availableStreams = new ArrayList<>(videos);
|
||||||
@ -337,41 +339,55 @@ public abstract class VideoPlayer extends BasePlayer
|
|||||||
}
|
}
|
||||||
|
|
||||||
buildQualityMenu();
|
buildQualityMenu();
|
||||||
buildPlaybackSpeedMenu();
|
|
||||||
qualityTextView.setVisibility(View.VISIBLE);
|
qualityTextView.setVisibility(View.VISIBLE);
|
||||||
playbackSpeedTextView.setVisibility(View.VISIBLE);
|
surfaceView.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
surfaceView.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildPlaybackSpeedMenu();
|
||||||
|
playbackSpeedTextView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public MediaSource sourceOf(final PlayQueueItem item, final StreamInfo info) {
|
public MediaSource sourceOf(final PlayQueueItem item, final StreamInfo info) {
|
||||||
final List<VideoStream> videos = ListHelper.getSortedStreamVideosList(context, info.video_streams, info.video_only_streams, false);
|
List<MediaSource> mediaSources = new ArrayList<>();
|
||||||
|
|
||||||
|
// Create video stream source
|
||||||
|
final List<VideoStream> videos = ListHelper.getSortedStreamVideosList(context,
|
||||||
|
info.video_streams, info.video_only_streams, false);
|
||||||
final int index;
|
final int index;
|
||||||
if (playbackQuality == null) {
|
if (videos.isEmpty()) {
|
||||||
|
index = -1;
|
||||||
|
} else if (playbackQuality == null) {
|
||||||
index = getDefaultResolutionIndex(videos);
|
index = getDefaultResolutionIndex(videos);
|
||||||
} else {
|
} else {
|
||||||
index = getOverrideResolutionIndex(videos, getPlaybackQuality());
|
index = getOverrideResolutionIndex(videos, getPlaybackQuality());
|
||||||
}
|
}
|
||||||
if (index < 0 || index >= videos.size()) return null;
|
final VideoStream video = index >= 0 && index < videos.size() ? videos.get(index) : null;
|
||||||
final VideoStream video = videos.get(index);
|
if (video != null) {
|
||||||
|
|
||||||
List<MediaSource> mediaSources = new ArrayList<>();
|
|
||||||
// Create video stream source
|
|
||||||
final MediaSource streamSource = buildMediaSource(video.getUrl(),
|
final MediaSource streamSource = buildMediaSource(video.getUrl(),
|
||||||
MediaFormat.getSuffixById(video.getFormatId()));
|
MediaFormat.getSuffixById(video.getFormatId()));
|
||||||
mediaSources.add(streamSource);
|
mediaSources.add(streamSource);
|
||||||
|
}
|
||||||
|
|
||||||
// Create optional audio stream source
|
// Create optional audio stream source
|
||||||
final AudioStream audio = ListHelper.getHighestQualityAudio(info.audio_streams);
|
final List<AudioStream> audioStreams = info.getAudioStreams();
|
||||||
if (video.isVideoOnly && audio != null) {
|
final AudioStream audio = audioStreams.isEmpty() ? null : audioStreams.get(
|
||||||
|
ListHelper.getDefaultAudioFormat(context, audioStreams));
|
||||||
|
// Use the audio stream if there is no video stream, or
|
||||||
// Merge with audio stream in case if video does not contain audio
|
// Merge with audio stream in case if video does not contain audio
|
||||||
|
if (audio != null && ((video != null && video.isVideoOnly) || video == null)) {
|
||||||
final MediaSource audioSource = buildMediaSource(audio.getUrl(),
|
final MediaSource audioSource = buildMediaSource(audio.getUrl(),
|
||||||
MediaFormat.getSuffixById(audio.getFormatId()));
|
MediaFormat.getSuffixById(audio.getFormatId()));
|
||||||
mediaSources.add(audioSource);
|
mediaSources.add(audioSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there is no audio or video sources, then this media source cannot be played back
|
||||||
|
if (mediaSources.isEmpty()) return null;
|
||||||
|
// Below are auxiliary media sources
|
||||||
|
|
||||||
// Create subtitle sources
|
// Create subtitle sources
|
||||||
for (final Subtitles subtitle : info.getSubtitles()) {
|
for (final Subtitles subtitle : info.getSubtitles()) {
|
||||||
final String mimeType = PlayerHelper.mimeTypesOf(subtitle.getFileType());
|
final String mimeType = PlayerHelper.mimeTypesOf(subtitle.getFileType());
|
||||||
@ -658,8 +674,10 @@ public abstract class VideoPlayer extends BasePlayer
|
|||||||
public void onDismiss(PopupMenu menu) {
|
public void onDismiss(PopupMenu menu) {
|
||||||
if (DEBUG) Log.d(TAG, "onDismiss() called with: menu = [" + menu + "]");
|
if (DEBUG) Log.d(TAG, "onDismiss() called with: menu = [" + menu + "]");
|
||||||
isSomePopupMenuVisible = false;
|
isSomePopupMenuVisible = false;
|
||||||
|
if (getSelectedVideoStream() != null) {
|
||||||
qualityTextView.setText(getSelectedVideoStream().resolution);
|
qualityTextView.setText(getSelectedVideoStream().resolution);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void onQualitySelectorClicked() {
|
public void onQualitySelectorClicked() {
|
||||||
if (DEBUG) Log.d(TAG, "onQualitySelectorClicked() called");
|
if (DEBUG) Log.d(TAG, "onQualitySelectorClicked() called");
|
||||||
@ -668,8 +686,12 @@ public abstract class VideoPlayer extends BasePlayer
|
|||||||
showControls(300);
|
showControls(300);
|
||||||
|
|
||||||
final VideoStream videoStream = getSelectedVideoStream();
|
final VideoStream videoStream = getSelectedVideoStream();
|
||||||
final String qualityText = MediaFormat.getNameById(videoStream.format) + " " + videoStream.resolution;
|
if (videoStream != null) {
|
||||||
|
final String qualityText = MediaFormat.getNameById(videoStream.getFormatId()) + " "
|
||||||
|
+ videoStream.resolution;
|
||||||
qualityTextView.setText(qualityText);
|
qualityTextView.setText(qualityText);
|
||||||
|
}
|
||||||
|
|
||||||
wasPlaying = simpleExoPlayer.getPlayWhenReady();
|
wasPlaying = simpleExoPlayer.getPlayWhenReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -864,8 +886,11 @@ public abstract class VideoPlayer extends BasePlayer
|
|||||||
return wasPlaying;
|
return wasPlaying;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public VideoStream getSelectedVideoStream() {
|
public VideoStream getSelectedVideoStream() {
|
||||||
return availableStreams.get(selectedStreamIndex);
|
return (selectedStreamIndex >= 0 && availableStreams != null &&
|
||||||
|
availableStreams.size() > selectedStreamIndex) ?
|
||||||
|
availableStreams.get(selectedStreamIndex) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Handler getControlsVisibilityHandler() {
|
public Handler getControlsVisibilityHandler() {
|
||||||
|
@ -412,7 +412,7 @@
|
|||||||
<string name="larger_caption_font_size">Larger Font</string>
|
<string name="larger_caption_font_size">Larger Font</string>
|
||||||
|
|
||||||
<!-- Debug Only -->
|
<!-- Debug Only -->
|
||||||
<string name="toggle_leak_canary">Monitor Leaks</string>
|
<string name="toggle_leak_canary" translatable="false">LeakCanary</string>
|
||||||
<string name="enable_leak_canary_notice">Memory leak monitoring enabled, app may become unresponsive when heap dumping</string>
|
<string name="enable_leak_canary_notice">Memory leak monitoring enabled, app may become unresponsive when heap dumping</string>
|
||||||
<string name="disable_leak_canary_notice">Memory leak monitoring disabled</string>
|
<string name="disable_leak_canary_notice">Memory leak monitoring disabled</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user