Search in sources :

Example 6 with VideoStream

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

the class VideoPlayer method buildQualityMenu.

/*//////////////////////////////////////////////////////////////////////////
    // UI Builders
    //////////////////////////////////////////////////////////////////////////*/
public void buildQualityMenu() {
    if (qualityPopupMenu == null)
        return;
    qualityPopupMenu.getMenu().removeGroup(qualityPopupMenuGroupId);
    for (int i = 0; i < availableStreams.size(); i++) {
        VideoStream videoStream = availableStreams.get(i);
        qualityPopupMenu.getMenu().add(qualityPopupMenuGroupId, i, Menu.NONE, MediaFormat.getNameById(videoStream.getFormatId()) + " " + videoStream.resolution);
    }
    if (getSelectedVideoStream() != null) {
        qualityTextView.setText(getSelectedVideoStream().resolution);
    }
    qualityPopupMenu.setOnMenuItemClickListener(this);
    qualityPopupMenu.setOnDismissListener(this);
}
Also used : VideoStream(org.schabi.newpipe.extractor.stream.VideoStream)

Example 7 with VideoStream

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

the class NavigationHelper method playOnExternalVideoPlayer.

public static void playOnExternalVideoPlayer(Context context, StreamInfo info) {
    ArrayList<VideoStream> videoStreamsList = new ArrayList<>(ListHelper.getSortedStreamVideosList(context, info.getVideoStreams(), null, false));
    int index = ListHelper.getDefaultResolutionIndex(context, videoStreamsList);
    if (index == -1) {
        Toast.makeText(context, R.string.video_streams_empty, Toast.LENGTH_SHORT).show();
        return;
    }
    VideoStream videoStream = videoStreamsList.get(index);
    playOnExternalPlayer(context, info.getName(), info.getUploaderName(), videoStream);
}
Also used : VideoStream(org.schabi.newpipe.extractor.stream.VideoStream) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint)

Example 8 with VideoStream

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

the class NavigationHelper method playOnOldVideoPlayer.

public static void playOnOldVideoPlayer(Context context, StreamInfo info) {
    ArrayList<VideoStream> videoStreamsList = new ArrayList<>(ListHelper.getSortedStreamVideosList(context, info.getVideoStreams(), null, false));
    int index = ListHelper.getDefaultResolutionIndex(context, videoStreamsList);
    if (index == -1) {
        Toast.makeText(context, R.string.video_streams_empty, Toast.LENGTH_SHORT).show();
        return;
    }
    VideoStream videoStream = videoStreamsList.get(index);
    Intent intent = new Intent(context, PlayVideoActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).putExtra(PlayVideoActivity.VIDEO_TITLE, info.getName()).putExtra(PlayVideoActivity.STREAM_URL, videoStream.getUrl()).putExtra(PlayVideoActivity.VIDEO_URL, info.getUrl()).putExtra(PlayVideoActivity.START_POSITION, info.getStartPosition());
    context.startActivity(intent);
}
Also used : VideoStream(org.schabi.newpipe.extractor.stream.VideoStream) ArrayList(java.util.ArrayList) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint) PlayVideoActivity(org.schabi.newpipe.player.old.PlayVideoActivity)

Example 9 with VideoStream

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

the class VideoPlayer method sourceOf.

@Override
@Nullable
public MediaSource sourceOf(final PlayQueueItem item, final StreamInfo info) {
    final MediaSource liveSource = super.sourceOf(item, info);
    if (liveSource != null)
        return liveSource;
    List<MediaSource> mediaSources = new ArrayList<>();
    // Create video stream source
    final List<VideoStream> videos = ListHelper.getSortedStreamVideosList(context, info.getVideoStreams(), info.getVideoOnlyStreams(), false);
    final int index;
    if (videos.isEmpty()) {
        index = -1;
    } else if (playbackQuality == null) {
        index = getDefaultResolutionIndex(videos);
    } else {
        index = getOverrideResolutionIndex(videos, getPlaybackQuality());
    }
    final VideoStream video = index >= 0 && index < videos.size() ? videos.get(index) : null;
    if (video != null) {
        final MediaSource streamSource = buildMediaSource(video.getUrl(), PlayerHelper.cacheKeyOf(info, video), MediaFormat.getSuffixById(video.getFormatId()));
        mediaSources.add(streamSource);
    }
    // Create optional audio stream source
    final List<AudioStream> audioStreams = info.getAudioStreams();
    final AudioStream audio = audioStreams.isEmpty() ? null : audioStreams.get(ListHelper.getDefaultAudioFormat(context, audioStreams));
    // 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(), PlayerHelper.cacheKeyOf(info, audio), MediaFormat.getSuffixById(audio.getFormatId()));
        mediaSources.add(audioSource);
    }
    // If there is no audio or video sources, then this media source cannot be played back
    if (mediaSources.isEmpty())
        return null;
    // Create subtitle sources
    for (final Subtitles subtitle : info.getSubtitles()) {
        final String mimeType = PlayerHelper.mimeTypesOf(subtitle.getFileType());
        if (mimeType == null)
            continue;
        final Format textFormat = Format.createTextSampleFormat(null, mimeType, SELECTION_FLAG_AUTOSELECT, PlayerHelper.captionLanguageOf(context, subtitle));
        final MediaSource textSource = dataSource.getSampleMediaSourceFactory().createMediaSource(Uri.parse(subtitle.getURL()), textFormat, TIME_UNSET);
        mediaSources.add(textSource);
    }
    if (mediaSources.size() == 1) {
        return mediaSources.get(0);
    } else {
        return new MergingMediaSource(mediaSources.toArray(new MediaSource[mediaSources.size()]));
    }
}
Also used : AudioStream(org.schabi.newpipe.extractor.stream.AudioStream) Format(com.google.android.exoplayer2.Format) MediaFormat(org.schabi.newpipe.extractor.MediaFormat) MediaSource(com.google.android.exoplayer2.source.MediaSource) MergingMediaSource(com.google.android.exoplayer2.source.MergingMediaSource) MergingMediaSource(com.google.android.exoplayer2.source.MergingMediaSource) Subtitles(org.schabi.newpipe.extractor.Subtitles) ArrayList(java.util.ArrayList) VideoStream(org.schabi.newpipe.extractor.stream.VideoStream) PlayerHelper.getTimeString(org.schabi.newpipe.player.helper.PlayerHelper.getTimeString) Nullable(android.support.annotation.Nullable)

Example 10 with VideoStream

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

the class DownloadDialog method onCreate.

/*//////////////////////////////////////////////////////////////////////////
    // LifeCycle
    //////////////////////////////////////////////////////////////////////////*/
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (DEBUG)
        Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]");
    if (!PermissionHelper.checkStoragePermissions(getActivity())) {
        getDialog().dismiss();
        return;
    }
    if (savedInstanceState != null) {
        Serializable serial = savedInstanceState.getSerializable(INFO_KEY);
        if (serial instanceof StreamInfo)
            currentInfo = (StreamInfo) serial;
        serial = savedInstanceState.getSerializable(SORTED_VIDEOS_LIST_KEY);
        if (serial instanceof ArrayList) {
            // noinspection unchecked
            sortedStreamVideosList = (ArrayList<VideoStream>) serial;
        }
        selectedVideoIndex = savedInstanceState.getInt(SELECTED_VIDEO_KEY, 0);
        selectedAudioIndex = savedInstanceState.getInt(SELECTED_AUDIO_KEY, 0);
    }
}
Also used : Serializable(java.io.Serializable) StreamInfo(org.schabi.newpipe.extractor.stream.StreamInfo) ArrayList(java.util.ArrayList) 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