Search in sources :

Example 1 with AudioStream

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);
}
Also used : AudioStream(org.schabi.newpipe.extractor.stream.AudioStream) SuppressLint(android.annotation.SuppressLint)

Example 2 with 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());
}
Also used : AudioStream(org.schabi.newpipe.extractor.stream.AudioStream) Test(org.junit.Test)

Example 3 with AudioStream

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());
}
Also used : AudioStream(org.schabi.newpipe.extractor.stream.AudioStream) Test(org.junit.Test)

Example 4 with AudioStream

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);
}
Also used : AudioStream(org.schabi.newpipe.extractor.stream.AudioStream) ArrayAdapter(android.widget.ArrayAdapter)

Example 5 with AudioStream

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);
    }
}
Also used : AudioStream(org.schabi.newpipe.extractor.stream.AudioStream)

Aggregations

AudioStream (org.schabi.newpipe.extractor.stream.AudioStream)6 Test (org.junit.Test)2 SuppressLint (android.annotation.SuppressLint)1 Nullable (android.support.annotation.Nullable)1 ArrayAdapter (android.widget.ArrayAdapter)1 Format (com.google.android.exoplayer2.Format)1 MediaSource (com.google.android.exoplayer2.source.MediaSource)1 MergingMediaSource (com.google.android.exoplayer2.source.MergingMediaSource)1 ArrayList (java.util.ArrayList)1 MediaFormat (org.schabi.newpipe.extractor.MediaFormat)1 Subtitles (org.schabi.newpipe.extractor.Subtitles)1 VideoStream (org.schabi.newpipe.extractor.stream.VideoStream)1 PlayerHelper.getTimeString (org.schabi.newpipe.player.helper.PlayerHelper.getTimeString)1