mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-25 04:22:30 +01:00
commit
3f94e7b638
@ -7,8 +7,6 @@ import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.DialogInterface.OnDismissListener;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
@ -113,14 +111,11 @@ public class DownloadDialog extends DialogFragment
|
|||||||
@State
|
@State
|
||||||
int selectedSubtitleIndex = 0; // default to the first item
|
int selectedSubtitleIndex = 0; // default to the first item
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private OnDismissListener onDismissListener = null;
|
|
||||||
|
|
||||||
private StoredDirectoryHelper mainStorageAudio = null;
|
private StoredDirectoryHelper mainStorageAudio = null;
|
||||||
private StoredDirectoryHelper mainStorageVideo = null;
|
private StoredDirectoryHelper mainStorageVideo = null;
|
||||||
private DownloadManager downloadManager = null;
|
private DownloadManager downloadManager = null;
|
||||||
private ActionMenuItemView okButton = null;
|
private ActionMenuItemView okButton = null;
|
||||||
private Context context;
|
private Context context = null;
|
||||||
private boolean askForSavePath;
|
private boolean askForSavePath;
|
||||||
|
|
||||||
private AudioTrackAdapter audioTrackAdapter;
|
private AudioTrackAdapter audioTrackAdapter;
|
||||||
@ -195,13 +190,6 @@ public class DownloadDialog extends DialogFragment
|
|||||||
this.selectedVideoIndex = ListHelper.getDefaultResolutionIndex(context, videoStreams);
|
this.selectedVideoIndex = ListHelper.getDefaultResolutionIndex(context, videoStreams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param onDismissListener the listener to call in {@link #onDismiss(DialogInterface)}
|
|
||||||
*/
|
|
||||||
public void setOnDismissListener(@Nullable final OnDismissListener onDismissListener) {
|
|
||||||
this.onDismissListener = onDismissListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Android lifecycle
|
// Android lifecycle
|
||||||
@ -221,6 +209,8 @@ public class DownloadDialog extends DialogFragment
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// context will remain null if dismiss() was called above, allowing to check whether the
|
||||||
|
// dialog is being dismissed in onViewCreated()
|
||||||
context = getContext();
|
context = getContext();
|
||||||
|
|
||||||
setStyle(STYLE_NO_TITLE, ThemeHelper.getDialogTheme(context));
|
setStyle(STYLE_NO_TITLE, ThemeHelper.getDialogTheme(context));
|
||||||
@ -305,6 +295,9 @@ public class DownloadDialog extends DialogFragment
|
|||||||
@Nullable final Bundle savedInstanceState) {
|
@Nullable final Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
dialogBinding = DownloadDialogBinding.bind(view);
|
dialogBinding = DownloadDialogBinding.bind(view);
|
||||||
|
if (context == null) {
|
||||||
|
return; // the dialog is being dismissed, see the call to dismiss() in onCreate()
|
||||||
|
}
|
||||||
|
|
||||||
dialogBinding.fileName.setText(FilenameUtils.createFilename(getContext(),
|
dialogBinding.fileName.setText(FilenameUtils.createFilename(getContext(),
|
||||||
currentInfo.getName()));
|
currentInfo.getName()));
|
||||||
@ -364,14 +357,6 @@ public class DownloadDialog extends DialogFragment
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDismiss(@NonNull final DialogInterface dialog) {
|
|
||||||
super.onDismiss(dialog);
|
|
||||||
if (onDismissListener != null) {
|
|
||||||
onDismissListener.onDismiss(dialog);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
@ -11,7 +11,6 @@ import org.schabi.newpipe.extractor.stream.Stream;
|
|||||||
import org.schabi.newpipe.extractor.stream.VideoStream;
|
import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||||
import org.schabi.newpipe.util.StreamItemAdapter.StreamInfoWrapper;
|
import org.schabi.newpipe.util.StreamItemAdapter.StreamInfoWrapper;
|
||||||
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SecondaryStreamHelper<T extends Stream> {
|
public class SecondaryStreamHelper<T extends Stream> {
|
||||||
@ -43,42 +42,27 @@ public class SecondaryStreamHelper<T extends Stream> {
|
|||||||
@NonNull final List<AudioStream> audioStreams,
|
@NonNull final List<AudioStream> audioStreams,
|
||||||
@NonNull final VideoStream videoStream) {
|
@NonNull final VideoStream videoStream) {
|
||||||
final MediaFormat mediaFormat = videoStream.getFormat();
|
final MediaFormat mediaFormat = videoStream.getFormat();
|
||||||
if (mediaFormat == null) {
|
|
||||||
|
if (mediaFormat == MediaFormat.WEBM) {
|
||||||
|
return audioStreams
|
||||||
|
.stream()
|
||||||
|
.filter(audioStream -> audioStream.getFormat() == MediaFormat.WEBMA
|
||||||
|
|| audioStream.getFormat() == MediaFormat.WEBMA_OPUS)
|
||||||
|
.max(ListHelper.getAudioFormatComparator(MediaFormat.WEBMA,
|
||||||
|
ListHelper.isLimitingDataUsage(context)))
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
} else if (mediaFormat == MediaFormat.MPEG_4) {
|
||||||
|
return audioStreams
|
||||||
|
.stream()
|
||||||
|
.filter(audioStream -> audioStream.getFormat() == MediaFormat.M4A)
|
||||||
|
.max(ListHelper.getAudioFormatComparator(MediaFormat.M4A,
|
||||||
|
ListHelper.isLimitingDataUsage(context)))
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (mediaFormat) {
|
|
||||||
case WEBM:
|
|
||||||
case MPEG_4: // Is MPEG-4 DASH?
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final boolean m4v = mediaFormat == MediaFormat.MPEG_4;
|
|
||||||
final boolean isLimitingDataUsage = ListHelper.isLimitingDataUsage(context);
|
|
||||||
|
|
||||||
Comparator<AudioStream> comparator = ListHelper.getAudioFormatComparator(
|
|
||||||
m4v ? MediaFormat.M4A : MediaFormat.WEBMA, isLimitingDataUsage);
|
|
||||||
int preferredAudioStreamIndex = ListHelper.getAudioIndexByHighestRank(
|
|
||||||
audioStreams, comparator);
|
|
||||||
|
|
||||||
if (preferredAudioStreamIndex == -1) {
|
|
||||||
if (m4v) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
comparator = ListHelper.getAudioFormatComparator(
|
|
||||||
MediaFormat.WEBMA_OPUS, isLimitingDataUsage);
|
|
||||||
preferredAudioStreamIndex = ListHelper.getAudioIndexByHighestRank(
|
|
||||||
audioStreams, comparator);
|
|
||||||
|
|
||||||
if (preferredAudioStreamIndex == -1) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return audioStreams.get(preferredAudioStreamIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public T getStream() {
|
public T getStream() {
|
||||||
|
@ -411,7 +411,7 @@ public class DownloadManagerService extends Service {
|
|||||||
mission.threadCount = threads;
|
mission.threadCount = threads;
|
||||||
mission.source = source;
|
mission.source = source;
|
||||||
mission.nearLength = nearLength;
|
mission.nearLength = nearLength;
|
||||||
mission.recoveryInfo = recovery.toArray(MissionRecoveryInfo[]::new);
|
mission.recoveryInfo = recovery.toArray(new MissionRecoveryInfo[0]);
|
||||||
|
|
||||||
if (ps != null)
|
if (ps != null)
|
||||||
ps.setTemporalDir(DownloadManager.pickAvailableTemporalDir(this));
|
ps.setTemporalDir(DownloadManager.pickAvailableTemporalDir(this));
|
||||||
|
Loading…
Reference in New Issue
Block a user