Search in sources :

Example 1 with VideoStream

use of org.schabi.newpipe.extractor.stream.VideoStream in project NewPipe by TeamNewPipe.

the class ListHelperTest method getDefaultResolutionTest.

@Test
public void getDefaultResolutionTest() throws Exception {
    List<VideoStream> testList = Arrays.asList(new VideoStream("", MediaFormat.MPEG_4, /**/
    "720p"), new VideoStream("", MediaFormat.v3GPP, /**/
    "240p"), new VideoStream("", MediaFormat.WEBM, /**/
    "480p"), new VideoStream("", MediaFormat.WEBM, /**/
    "240p"), new VideoStream("", MediaFormat.MPEG_4, /**/
    "240p"), new VideoStream("", MediaFormat.WEBM, /**/
    "144p"), new VideoStream("", MediaFormat.MPEG_4, /**/
    "360p"), new VideoStream("", MediaFormat.WEBM, /**/
    "360p"));
    VideoStream result = testList.get(ListHelper.getDefaultResolutionIndex("720p", BEST_RESOLUTION_KEY, MediaFormat.MPEG_4, testList));
    assertEquals("720p", result.resolution);
    assertEquals(MediaFormat.MPEG_4, result.getFormat());
    // Have resolution and the format
    result = testList.get(ListHelper.getDefaultResolutionIndex("480p", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
    assertEquals("480p", result.resolution);
    assertEquals(MediaFormat.WEBM, result.getFormat());
    // Have resolution but not the format
    result = testList.get(ListHelper.getDefaultResolutionIndex("480p", BEST_RESOLUTION_KEY, MediaFormat.MPEG_4, testList));
    assertEquals("480p", result.resolution);
    assertEquals(MediaFormat.WEBM, result.getFormat());
    // Have resolution and the format
    result = testList.get(ListHelper.getDefaultResolutionIndex("240p", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
    assertEquals("240p", result.resolution);
    assertEquals(MediaFormat.WEBM, result.getFormat());
    // The best resolution
    result = testList.get(ListHelper.getDefaultResolutionIndex(BEST_RESOLUTION_KEY, BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
    assertEquals("720p", result.resolution);
    assertEquals(MediaFormat.MPEG_4, result.getFormat());
    // Doesn't have the 60fps variant and format
    result = testList.get(ListHelper.getDefaultResolutionIndex("720p60", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
    assertEquals("720p", result.resolution);
    assertEquals(MediaFormat.MPEG_4, result.getFormat());
    // Doesn't have the 60fps variant
    result = testList.get(ListHelper.getDefaultResolutionIndex("480p60", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
    assertEquals("480p", result.resolution);
    assertEquals(MediaFormat.WEBM, result.getFormat());
    // Doesn't have the resolution, will return the best one
    result = testList.get(ListHelper.getDefaultResolutionIndex("2160p60", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
    assertEquals("720p", result.resolution);
    assertEquals(MediaFormat.MPEG_4, result.getFormat());
}
Also used : VideoStream(org.schabi.newpipe.extractor.stream.VideoStream) Test(org.junit.Test)

Example 2 with VideoStream

use of org.schabi.newpipe.extractor.stream.VideoStream in project NewPipe by TeamNewPipe.

the class ListHelper method getSortedStreamVideosList.

/**
 * Join the two lists of video streams (video_only and normal videos), and sort them according with default format
 * chosen by the user
 *
 * @param defaultFormat       format to give preference
 * @param showHigherResolutions show >1080p resolutions
 * @param videoStreams          normal videos list
 * @param videoOnlyStreams      video only stream list
 * @param ascendingOrder        true -> smallest to greatest | false -> greatest to smallest    @return the sorted list
 * @return the sorted list
 */
public static List<VideoStream> getSortedStreamVideosList(MediaFormat defaultFormat, boolean showHigherResolutions, List<VideoStream> videoStreams, List<VideoStream> videoOnlyStreams, boolean ascendingOrder) {
    ArrayList<VideoStream> retList = new ArrayList<>();
    HashMap<String, VideoStream> hashMap = new HashMap<>();
    if (videoOnlyStreams != null) {
        for (VideoStream stream : videoOnlyStreams) {
            if (!showHigherResolutions && HIGH_RESOLUTION_LIST.contains(stream.getResolution()))
                continue;
            retList.add(stream);
        }
    }
    if (videoStreams != null) {
        for (VideoStream stream : videoStreams) {
            if (!showHigherResolutions && HIGH_RESOLUTION_LIST.contains(stream.getResolution()))
                continue;
            retList.add(stream);
        }
    }
    // Add all to the hashmap
    for (VideoStream videoStream : retList) hashMap.put(videoStream.getResolution(), videoStream);
    // Override the values when the key == resolution, with the defaultFormat
    for (VideoStream videoStream : retList) {
        if (videoStream.getFormat() == defaultFormat)
            hashMap.put(videoStream.getResolution(), videoStream);
    }
    retList.clear();
    retList.addAll(hashMap.values());
    sortStreamList(retList, ascendingOrder);
    return retList;
}
Also used : HashMap(java.util.HashMap) VideoStream(org.schabi.newpipe.extractor.stream.VideoStream) ArrayList(java.util.ArrayList)

Example 3 with VideoStream

use of org.schabi.newpipe.extractor.stream.VideoStream in project NewPipe by TeamNewPipe.

the class SpinnerToolbarAdapter method getCustomView.

private View getCustomView(int position, View convertView, ViewGroup parent, boolean isDropdownItem) {
    if (convertView == null) {
        convertView = LayoutInflater.from(context).inflate(R.layout.resolutions_spinner_item, parent, false);
    }
    ImageView woSoundIcon = convertView.findViewById(R.id.wo_sound_icon);
    TextView text = convertView.findViewById(android.R.id.text1);
    VideoStream item = (VideoStream) getItem(position);
    text.setText(item.getFormat().getName() + " " + item.getResolution());
    int visibility = !showIconNoAudio ? View.GONE : item.isVideoOnly ? View.VISIBLE : isDropdownItem ? View.INVISIBLE : View.GONE;
    woSoundIcon.setVisibility(visibility);
    return convertView;
}
Also used : VideoStream(org.schabi.newpipe.extractor.stream.VideoStream) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 4 with VideoStream

use of org.schabi.newpipe.extractor.stream.VideoStream in project NewPipe by TeamNewPipe.

the class VideoPlayer method onQualitySelectorClicked.

public void onQualitySelectorClicked() {
    if (DEBUG)
        Log.d(TAG, "onQualitySelectorClicked() called");
    qualityPopupMenu.show();
    isSomePopupMenuVisible = true;
    showControls(DEFAULT_CONTROLS_DURATION);
    final VideoStream videoStream = getSelectedVideoStream();
    if (videoStream != null) {
        final String qualityText = MediaFormat.getNameById(videoStream.getFormatId()) + " " + videoStream.resolution;
        qualityTextView.setText(qualityText);
    }
    wasPlaying = simpleExoPlayer.getPlayWhenReady();
}
Also used : VideoStream(org.schabi.newpipe.extractor.stream.VideoStream) PlayerHelper.getTimeString(org.schabi.newpipe.player.helper.PlayerHelper.getTimeString)

Example 5 with VideoStream

use of org.schabi.newpipe.extractor.stream.VideoStream in project NewPipe by TeamNewPipe.

the class VideoPlayer method onMetadataChanged.

protected void onMetadataChanged(@NonNull final PlayQueueItem item, @Nullable final StreamInfo info, final int newPlayQueueIndex, final boolean hasPlayQueueItemChanged) {
    qualityTextView.setVisibility(View.GONE);
    playbackSpeedTextView.setVisibility(View.GONE);
    playbackEndTime.setVisibility(View.GONE);
    playbackLiveSync.setVisibility(View.GONE);
    final StreamType streamType = info == null ? StreamType.NONE : info.getStreamType();
    switch(streamType) {
        case AUDIO_STREAM:
            surfaceView.setVisibility(View.GONE);
            playbackEndTime.setVisibility(View.VISIBLE);
            break;
        case AUDIO_LIVE_STREAM:
            surfaceView.setVisibility(View.GONE);
            playbackLiveSync.setVisibility(View.VISIBLE);
            break;
        case LIVE_STREAM:
            surfaceView.setVisibility(View.VISIBLE);
            playbackLiveSync.setVisibility(View.VISIBLE);
            break;
        case VIDEO_STREAM:
            if (info.getVideoStreams().size() + info.getVideoOnlyStreams().size() == 0)
                break;
            final List<VideoStream> videos = ListHelper.getSortedStreamVideosList(context, info.getVideoStreams(), info.getVideoOnlyStreams(), false);
            availableStreams = new ArrayList<>(videos);
            if (playbackQuality == null) {
                selectedStreamIndex = getDefaultResolutionIndex(videos);
            } else {
                selectedStreamIndex = getOverrideResolutionIndex(videos, getPlaybackQuality());
            }
            buildQualityMenu();
            qualityTextView.setVisibility(View.VISIBLE);
            surfaceView.setVisibility(View.VISIBLE);
        default:
            playbackEndTime.setVisibility(View.VISIBLE);
            break;
    }
    buildPlaybackSpeedMenu();
    playbackSpeedTextView.setVisibility(View.VISIBLE);
}
Also used : StreamType(org.schabi.newpipe.extractor.stream.StreamType) VideoStream(org.schabi.newpipe.extractor.stream.VideoStream)

Aggregations

VideoStream (org.schabi.newpipe.extractor.stream.VideoStream)10 ArrayList (java.util.ArrayList)5 SuppressLint (android.annotation.SuppressLint)2 PlayerHelper.getTimeString (org.schabi.newpipe.player.helper.PlayerHelper.getTimeString)2 Intent (android.content.Intent)1 Nullable (android.support.annotation.Nullable)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Format (com.google.android.exoplayer2.Format)1 MediaSource (com.google.android.exoplayer2.source.MediaSource)1 MergingMediaSource (com.google.android.exoplayer2.source.MergingMediaSource)1 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 MediaFormat (org.schabi.newpipe.extractor.MediaFormat)1 Subtitles (org.schabi.newpipe.extractor.Subtitles)1 AudioStream (org.schabi.newpipe.extractor.stream.AudioStream)1 StreamInfo (org.schabi.newpipe.extractor.stream.StreamInfo)1 StreamType (org.schabi.newpipe.extractor.stream.StreamType)1 PlayVideoActivity (org.schabi.newpipe.player.old.PlayVideoActivity)1