use of org.schabi.newpipe.extractor.stream.AudioStream in project NewPipe by TeamNewPipe.
the class NavigationHelper method playOnExternalAudioPlayer.
/*//////////////////////////////////////////////////////////////////////////
// External Players
//////////////////////////////////////////////////////////////////////////*/
public static void playOnExternalAudioPlayer(Context context, StreamInfo info) {
final int index = ListHelper.getDefaultAudioFormat(context, info.getAudioStreams());
if (index == -1) {
Toast.makeText(context, R.string.audio_streams_empty, Toast.LENGTH_SHORT).show();
return;
}
AudioStream audioStream = info.getAudioStreams().get(index);
playOnExternalPlayer(context, info.getName(), info.getUploaderName(), audioStream);
}
use of org.schabi.newpipe.extractor.stream.AudioStream in project NewPipe by TeamNewPipe.
the class ListHelperTest method getHighestQualityAudioFormatTest.
@Test
public void getHighestQualityAudioFormatTest() throws Exception {
AudioStream stream = audioStreamsTestList.get(ListHelper.getHighestQualityAudioIndex(MediaFormat.M4A, audioStreamsTestList));
assertEquals(320, stream.average_bitrate);
assertEquals(MediaFormat.M4A, stream.getFormat());
stream = audioStreamsTestList.get(ListHelper.getHighestQualityAudioIndex(MediaFormat.WEBMA, audioStreamsTestList));
assertEquals(320, stream.average_bitrate);
assertEquals(MediaFormat.WEBMA, stream.getFormat());
stream = audioStreamsTestList.get(ListHelper.getHighestQualityAudioIndex(MediaFormat.MP3, audioStreamsTestList));
assertEquals(192, stream.average_bitrate);
assertEquals(MediaFormat.MP3, stream.getFormat());
}
use of org.schabi.newpipe.extractor.stream.AudioStream in project NewPipe by TeamNewPipe.
the class ListHelperTest method getHighestQualityAudioFormatPreferredAbsent.
@Test
public void getHighestQualityAudioFormatPreferredAbsent() throws Exception {
// ////////////////////////////////////////
// Doesn't contain the preferred format //
// //////////////////////////////////////
List<AudioStream> testList = Arrays.asList(new AudioStream("", MediaFormat.M4A, /**/
128), new AudioStream("", MediaFormat.WEBMA, /**/
192));
// List doesn't contains this format, it should fallback to the highest bitrate audio no matter what format it is
AudioStream stream = testList.get(ListHelper.getHighestQualityAudioIndex(MediaFormat.MP3, testList));
assertEquals(192, stream.average_bitrate);
assertEquals(MediaFormat.WEBMA, stream.getFormat());
// //////////////////////////////////////////////////////
// Multiple not-preferred-formats and equal bitrates //
// ////////////////////////////////////////////////////
testList = new ArrayList<>(Arrays.asList(new AudioStream("", MediaFormat.WEBMA, /**/
192), new AudioStream("", MediaFormat.M4A, /**/
192), new AudioStream("", MediaFormat.WEBMA, /**/
192), new AudioStream("", MediaFormat.M4A, /**/
192), new AudioStream("", MediaFormat.WEBMA, /**/
192), new AudioStream("", MediaFormat.M4A, /**/
192)));
// List doesn't contains this format, it should fallback to the highest bitrate audio no matter what format it is
// and as it have multiple with the same high value, the last one wins
stream = testList.get(ListHelper.getHighestQualityAudioIndex(MediaFormat.MP3, testList));
assertEquals(192, stream.average_bitrate);
assertEquals(MediaFormat.M4A, stream.getFormat());
// Again with a new element
testList.add(new AudioStream("", MediaFormat.WEBMA, /**/
192));
stream = testList.get(ListHelper.getHighestQualityAudioIndex(MediaFormat.MP3, testList));
assertEquals(192, stream.average_bitrate);
assertEquals(MediaFormat.WEBMA, stream.getFormat());
}
use of org.schabi.newpipe.extractor.stream.AudioStream in project NewPipe by TeamNewPipe.
the class DownloadDialog method setupAudioSpinner.
public void setupAudioSpinner(final List<AudioStream> audioStreams, Spinner spinner) {
String[] items = new String[audioStreams.size()];
for (int i = 0; i < audioStreams.size(); i++) {
AudioStream audioStream = audioStreams.get(i);
items[i] = audioStream.getFormat().getName() + " " + audioStream.getAverageBitrate() + "kbps";
}
ArrayAdapter<String> itemAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, items);
spinner.setAdapter(itemAdapter);
spinner.setSelection(selectedAudioIndex);
}
use of org.schabi.newpipe.extractor.stream.AudioStream in project NewPipe by TeamNewPipe.
the class VideoDetailFragment method openBackgroundPlayer.
/*//////////////////////////////////////////////////////////////////////////
// Play Utils
//////////////////////////////////////////////////////////////////////////*/
private void openBackgroundPlayer(final boolean append) {
AudioStream audioStream = currentInfo.getAudioStreams().get(ListHelper.getDefaultAudioFormat(activity, currentInfo.getAudioStreams()));
boolean useExternalAudioPlayer = PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(activity.getString(R.string.use_external_audio_player_key), false);
if (!useExternalAudioPlayer && android.os.Build.VERSION.SDK_INT >= 16) {
openNormalBackgroundPlayer(append);
} else {
NavigationHelper.playOnExternalPlayer(activity, currentInfo.getName(), currentInfo.getUploaderName(), audioStream);
}
}
Aggregations