Search in sources :

Example 1 with VideoStream

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

the class VideoItemDetailFragment method updateInfo.

private void updateInfo(final StreamInfo info) {
    Activity a = getActivity();
    RelativeLayout textContentLayout = (RelativeLayout) activity.findViewById(R.id.detail_text_content_layout);
    final TextView videoTitleView = (TextView) activity.findViewById(R.id.detail_video_title_view);
    TextView uploaderView = (TextView) activity.findViewById(R.id.detail_uploader_view);
    TextView viewCountView = (TextView) activity.findViewById(R.id.detail_view_count_view);
    TextView thumbsUpView = (TextView) activity.findViewById(R.id.detail_thumbs_up_count_view);
    TextView thumbsDownView = (TextView) activity.findViewById(R.id.detail_thumbs_down_count_view);
    TextView uploadDateView = (TextView) activity.findViewById(R.id.detail_upload_date_view);
    TextView descriptionView = (TextView) activity.findViewById(R.id.detail_description_view);
    RecyclerView nextStreamView = (RecyclerView) activity.findViewById(R.id.detail_next_stream_content);
    RelativeLayout nextVideoRootFrame = (RelativeLayout) activity.findViewById(R.id.detail_next_stream_root_layout);
    TextView similarTitle = (TextView) activity.findViewById(R.id.detail_similar_title);
    Button backgroundButton = (Button) activity.findViewById(R.id.detail_stream_thumbnail_window_background_button);
    View thumbnailView = activity.findViewById(R.id.detail_thumbnail_view);
    View topView = activity.findViewById(R.id.detailTopView);
    Button channelButton = (Button) activity.findViewById(R.id.channel_button);
    // prevents a crash if the activity/fragment was already left when the response came
    if (channelButton != null) {
        progressBar.setVisibility(View.GONE);
        if (info.next_video != null) {
            // todo: activate this function or remove it
            nextStreamView.setVisibility(View.GONE);
        } else {
            nextStreamView.setVisibility(View.GONE);
            activity.findViewById(R.id.detail_similar_title).setVisibility(View.GONE);
        }
        textContentLayout.setVisibility(View.VISIBLE);
        if (android.os.Build.VERSION.SDK_INT < 18) {
            playVideoButton.setVisibility(View.VISIBLE);
        } else {
            ImageView playArrowView = (ImageView) activity.findViewById(R.id.play_arrow_view);
            playArrowView.setVisibility(View.VISIBLE);
        }
        if (!showNextStreamItem) {
            nextVideoRootFrame.setVisibility(View.GONE);
            similarTitle.setVisibility(View.GONE);
        }
        videoTitleView.setText(info.title);
        topView.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == android.view.MotionEvent.ACTION_UP) {
                    ImageView arrow = (ImageView) activity.findViewById(R.id.toggle_description_view);
                    View extra = activity.findViewById(R.id.detailExtraView);
                    if (extra.getVisibility() == View.VISIBLE) {
                        extra.setVisibility(View.GONE);
                        arrow.setImageResource(R.drawable.arrow_down);
                    } else {
                        extra.setVisibility(View.VISIBLE);
                        arrow.setImageResource(R.drawable.arrow_up);
                    }
                }
                return true;
            }
        });
        // Since newpipe is designed to work even if certain information is not available,
        // the UI has to react on missing information.
        videoTitleView.setText(info.title);
        if (!info.uploader.isEmpty()) {
            uploaderView.setText(info.uploader);
        } else {
            activity.findViewById(R.id.detail_uploader_view).setVisibility(View.GONE);
        }
        if (info.view_count >= 0) {
            viewCountView.setText(Localization.localizeViewCount(info.view_count, a));
        } else {
            viewCountView.setVisibility(View.GONE);
        }
        if (info.dislike_count >= 0) {
            thumbsDownView.setText(Localization.localizeNumber(info.dislike_count, a));
        } else {
            thumbsDownView.setVisibility(View.INVISIBLE);
            activity.findViewById(R.id.detail_thumbs_down_count_view).setVisibility(View.GONE);
        }
        if (info.like_count >= 0) {
            thumbsUpView.setText(Localization.localizeNumber(info.like_count, a));
        } else {
            thumbsUpView.setVisibility(View.GONE);
            activity.findViewById(R.id.detail_thumbs_up_img_view).setVisibility(View.GONE);
            thumbsDownView.setVisibility(View.GONE);
            activity.findViewById(R.id.detail_thumbs_down_img_view).setVisibility(View.GONE);
        }
        if (!info.upload_date.isEmpty()) {
            uploadDateView.setText(Localization.localizeDate(info.upload_date, a));
        } else {
            uploadDateView.setVisibility(View.GONE);
        }
        if (!info.description.isEmpty()) {
            descriptionView.setText(Html.fromHtml(info.description));
        } else {
            descriptionView.setVisibility(View.GONE);
        }
        descriptionView.setMovementMethod(LinkMovementMethod.getInstance());
        // parse streams
        Vector<VideoStream> streamsToUse = new Vector<>();
        for (VideoStream i : info.video_streams) {
            if (useStream(i, streamsToUse)) {
                streamsToUse.add(i);
            }
        }
        textContentLayout.setVisibility(View.VISIBLE);
        if (info.next_video == null) {
            activity.findViewById(R.id.detail_next_stream_title).setVisibility(View.GONE);
        }
        if (info.related_streams != null && !info.related_streams.isEmpty()) {
            initSimilarVideos(info);
        } else {
            activity.findViewById(R.id.detail_similar_title).setVisibility(View.GONE);
            activity.findViewById(R.id.similar_streams_view).setVisibility(View.GONE);
        }
        setupActionBarHandler(info);
        if (autoPlayEnabled) {
            playVideo(info);
        }
        if (android.os.Build.VERSION.SDK_INT < 18) {
            playVideoButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    playVideo(info);
                }
            });
        }
        backgroundButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                playVideo(info);
            }
        });
        //todo: make backgroundButton handle this
        thumbnailView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                playVideo(info);
            }
        });
        if (info.channel_url != null && info.channel_url != "") {
            channelButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    NavStack.getInstance().openChannelActivity(getActivity(), info.channel_url, info.service_id);
                }
            });
        } else {
            channelButton.setVisibility(Button.GONE);
        }
        initThumbnailViews(info);
    }
}
Also used : VideoStream(org.schabi.newpipe.extractor.stream_info.VideoStream) ReCaptchaActivity(org.schabi.newpipe.ReCaptchaActivity) ExoPlayerActivity(org.schabi.newpipe.player.ExoPlayerActivity) AppCompatActivity(android.support.v7.app.AppCompatActivity) PlayVideoActivity(org.schabi.newpipe.player.PlayVideoActivity) ErrorActivity(org.schabi.newpipe.report.ErrorActivity) Activity(android.app.Activity) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) MotionEvent(android.view.MotionEvent) Button(android.widget.Button) FloatingActionButton(android.support.design.widget.FloatingActionButton) RelativeLayout(android.widget.RelativeLayout) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ImageView(android.widget.ImageView) Vector(java.util.Vector)

Example 2 with VideoStream

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

the class VideoItemDetailFragment method playVideo.

public void playVideo(final StreamInfo info) {
    // ----------- THE MAGIC MOMENT ---------------
    VideoStream selectedVideoStream = info.video_streams.get(actionBarHandler.getSelectedVideoStream());
    if (PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(activity.getString(R.string.use_external_video_player_key), false)) {
        // External Player
        Intent intent = new Intent();
        try {
            intent.setAction(Intent.ACTION_VIEW).setDataAndType(Uri.parse(selectedVideoStream.url), MediaFormat.getMimeById(selectedVideoStream.format)).putExtra(Intent.EXTRA_TITLE, info.title).putExtra("title", info.title);
            // HERE !!!
            activity.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setMessage(R.string.no_player_found).setPositiveButton(R.string.install, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent().setAction(Intent.ACTION_VIEW).setData(Uri.parse(activity.getString(R.string.fdroid_vlc_url)));
                    activity.startActivity(intent);
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            });
            builder.create().show();
        }
    } else {
        if (PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(activity.getString(R.string.use_exoplayer_key), false)) {
            // TODO: Fix this mess
            if (streamThumbnail != null)
                ActivityCommunicator.getCommunicator().backgroundPlayerThumbnail = streamThumbnail;
            if (info.dashMpdUrl != null && !info.dashMpdUrl.isEmpty()) {
                // try dash
                Intent intent = new Intent(activity, ExoPlayerActivity.class).setData(Uri.parse(info.dashMpdUrl));
                //.putExtra(ExoPlayerActivity.CONTENT_TYPE_EXTRA, Util.TYPE_DASH);
                startActivity(intent);
            } else if ((info.audio_streams != null && !info.audio_streams.isEmpty()) && (info.video_only_streams != null && !info.video_only_streams.isEmpty())) {
            // try smooth streaming
            } else {
                //default streaming
                Intent intent = new Intent(activity, ExoPlayerActivity.class).setDataAndType(Uri.parse(selectedVideoStream.url), MediaFormat.getMimeById(selectedVideoStream.format)).putExtra(ExoPlayerActivity.VIDEO_TITLE, info.title).putExtra(ExoPlayerActivity.CHANNEL_NAME, info.uploader);
                //.putExtra(ExoPlayerActivity.CONTENT_TYPE_EXTRA, Util.TYPE_OTHER);
                // HERE !!!
                activity.startActivity(intent);
            }
        //-------------
        } else {
            // Internal Player
            Intent intent = new Intent(activity, PlayVideoActivity.class).putExtra(PlayVideoActivity.VIDEO_TITLE, info.title).putExtra(PlayVideoActivity.STREAM_URL, selectedVideoStream.url).putExtra(PlayVideoActivity.VIDEO_URL, info.webpage_url).putExtra(PlayVideoActivity.START_POSITION, info.start_position);
            //also HERE !!!
            activity.startActivity(intent);
        }
    }
// --------------------------------------------
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) InfoItemBuilder(org.schabi.newpipe.info_list.InfoItemBuilder) VideoStream(org.schabi.newpipe.extractor.stream_info.VideoStream) Intent(android.content.Intent) Point(android.graphics.Point) ExoPlayerActivity(org.schabi.newpipe.player.ExoPlayerActivity)

Example 3 with VideoStream

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

the class YoutubeStreamExtractorDefaultTest method testGetVideoStreams.

@Test
public void testGetVideoStreams() throws ParsingException {
    for (VideoStream s : extractor.getVideoStreams()) {
        assertTrue(s.url, s.url.contains(HTTPS));
        assertTrue(s.resolution.length() > 0);
        assertTrue(Integer.toString(s.format), 0 <= s.format && s.format <= 4);
    }
}
Also used : VideoStream(org.schabi.newpipe.extractor.stream_info.VideoStream) Test(org.junit.Test)

Example 4 with VideoStream

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

the class ActionBarHandler method setupStreamList.

public void setupStreamList(final List<VideoStream> videoStreams) {
    if (activity != null) {
        selectedVideoStream = 0;
        // this array will be shown in the dropdown menu for selecting the stream/resolution.
        String[] itemArray = new String[videoStreams.size()];
        for (int i = 0; i < videoStreams.size(); i++) {
            VideoStream item = videoStreams.get(i);
            itemArray[i] = MediaFormat.getNameById(item.format) + " " + item.resolution;
        }
        int defaultResolution = getDefaultResolution(videoStreams);
        ArrayAdapter<String> itemAdapter = new ArrayAdapter<>(activity.getBaseContext(), android.R.layout.simple_spinner_dropdown_item, itemArray);
        ActionBar ab = activity.getSupportActionBar();
        //todo: make this throwsable
        assert ab != null : "Could not get actionbar";
        ab.setListNavigationCallbacks(itemAdapter, new ActionBar.OnNavigationListener() {

            @Override
            public boolean onNavigationItemSelected(int itemPosition, long itemId) {
                selectedVideoStream = (int) itemId;
                return true;
            }
        });
        ab.setSelectedNavigationItem(defaultResolution);
    }
}
Also used : VideoStream(org.schabi.newpipe.extractor.stream_info.VideoStream) ArrayAdapter(android.widget.ArrayAdapter) ActionBar(android.support.v7.app.ActionBar)

Example 5 with VideoStream

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

the class VideoItemDetailFragment method setupActionBarHandler.

private void setupActionBarHandler(final StreamInfo info) {
    actionBarHandler.setupStreamList(info.video_streams);
    actionBarHandler.setOnShareListener(new ActionBarHandler.OnActionListener() {

        @Override
        public void onActionSelected(int selectedStreamId) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SEND);
            intent.putExtra(Intent.EXTRA_TEXT, info.webpage_url);
            intent.setType("text/plain");
            activity.startActivity(Intent.createChooser(intent, activity.getString(R.string.share_dialog_title)));
        }
    });
    actionBarHandler.setOnOpenInBrowserListener(new ActionBarHandler.OnActionListener() {

        @Override
        public void onActionSelected(int selectedStreamId) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(info.webpage_url));
            activity.startActivity(Intent.createChooser(intent, activity.getString(R.string.choose_browser)));
        }
    });
    actionBarHandler.setOnOpenInPopupListener(new ActionBarHandler.OnActionListener() {

        @Override
        public void onActionSelected(int selectedStreamId) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !PermissionHelper.checkSystemAlertWindowPermission(activity)) {
                Toast.makeText(activity, R.string.msg_popup_permission, Toast.LENGTH_LONG).show();
                return;
            }
            if (streamThumbnail != null)
                ActivityCommunicator.getCommunicator().backgroundPlayerThumbnail = streamThumbnail;
            VideoStream selectedVideoStream = info.video_streams.get(selectedStreamId);
            Intent i = new Intent(activity, PopupVideoPlayer.class);
            Toast.makeText(activity, "Starting in popup mode", Toast.LENGTH_SHORT).show();
            i.putExtra(PopupVideoPlayer.VIDEO_TITLE, info.title).putExtra(PopupVideoPlayer.STREAM_URL, selectedVideoStream.url).putExtra(PopupVideoPlayer.CHANNEL_NAME, info.uploader).putExtra(PopupVideoPlayer.VIDEO_URL, info.webpage_url);
            activity.startService(i);
        }
    });
    actionBarHandler.setOnPlayWithKodiListener(new ActionBarHandler.OnActionListener() {

        @Override
        public void onActionSelected(int selectedStreamId) {
            try {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setPackage(KORE_PACKET);
                intent.setData(Uri.parse(info.webpage_url.replace("https", "http")));
                activity.startActivity(intent);
            } catch (Exception e) {
                e.printStackTrace();
                AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                builder.setMessage(R.string.kore_not_found).setPositiveButton(R.string.install, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent();
                        intent.setAction(Intent.ACTION_VIEW);
                        intent.setData(Uri.parse(activity.getString(R.string.fdroid_kore_url)));
                        activity.startActivity(intent);
                    }
                }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
                builder.create().show();
            }
        }
    });
    actionBarHandler.setOnDownloadListener(new ActionBarHandler.OnActionListener() {

        @Override
        public void onActionSelected(int selectedStreamId) {
            if (!PermissionHelper.checkStoragePermissions(getActivity())) {
                return;
            }
            try {
                Bundle args = new Bundle();
                if (info.audio_streams != null) {
                    AudioStream audioStream = info.audio_streams.get(getPreferredAudioStreamId(info));
                    String audioSuffix = "." + MediaFormat.getSuffixById(audioStream.format);
                    args.putString(DownloadDialog.AUDIO_URL, audioStream.url);
                    args.putString(DownloadDialog.FILE_SUFFIX_AUDIO, audioSuffix);
                }
                if (info.video_streams != null) {
                    VideoStream selectedStreamItem = info.video_streams.get(selectedStreamId);
                    String videoSuffix = "." + MediaFormat.getSuffixById(selectedStreamItem.format);
                    args.putString(DownloadDialog.FILE_SUFFIX_VIDEO, videoSuffix);
                    args.putString(DownloadDialog.VIDEO_URL, selectedStreamItem.url);
                }
                args.putString(DownloadDialog.TITLE, info.title);
                DownloadDialog downloadDialog = DownloadDialog.newInstance(args);
                downloadDialog.show(activity.getSupportFragmentManager(), "downloadDialog");
            } catch (Exception e) {
                Toast.makeText(VideoItemDetailFragment.this.getActivity(), R.string.could_not_setup_download_menu, Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }
        }
    });
    if (info.audio_streams == null) {
        actionBarHandler.showAudioAction(false);
    } else {
        actionBarHandler.setOnPlayAudioListener(new ActionBarHandler.OnActionListener() {

            @Override
            public void onActionSelected(int selectedStreamId) {
                boolean useExternalAudioPlayer = PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(activity.getString(R.string.use_external_audio_player_key), false);
                Intent intent;
                AudioStream audioStream = info.audio_streams.get(getPreferredAudioStreamId(info));
                if (!useExternalAudioPlayer && android.os.Build.VERSION.SDK_INT >= 18) {
                    //internal music player: explicit intent
                    if (!BackgroundPlayer.isRunning && streamThumbnail != null) {
                        ActivityCommunicator.getCommunicator().backgroundPlayerThumbnail = streamThumbnail;
                        intent = new Intent(activity, BackgroundPlayer.class);
                        intent.setAction(Intent.ACTION_VIEW);
                        Log.i(TAG, "audioStream is null:" + (audioStream == null));
                        Log.i(TAG, "audioStream.url is null:" + (audioStream.url == null));
                        intent.setDataAndType(Uri.parse(audioStream.url), MediaFormat.getMimeById(audioStream.format));
                        intent.putExtra(BackgroundPlayer.TITLE, info.title);
                        intent.putExtra(BackgroundPlayer.WEB_URL, info.webpage_url);
                        intent.putExtra(BackgroundPlayer.SERVICE_ID, streamingServiceId);
                        intent.putExtra(BackgroundPlayer.CHANNEL_NAME, info.uploader);
                        activity.startService(intent);
                    }
                } else {
                    intent = new Intent();
                    try {
                        intent.setAction(Intent.ACTION_VIEW);
                        intent.setDataAndType(Uri.parse(audioStream.url), MediaFormat.getMimeById(audioStream.format));
                        intent.putExtra(Intent.EXTRA_TITLE, info.title);
                        intent.putExtra("title", info.title);
                        // HERE !!!
                        activity.startActivity(intent);
                    } catch (Exception e) {
                        e.printStackTrace();
                        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                        builder.setMessage(R.string.no_player_found).setPositiveButton(R.string.install, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Intent intent = new Intent();
                                intent.setAction(Intent.ACTION_VIEW);
                                intent.setData(Uri.parse(activity.getString(R.string.fdroid_vlc_url)));
                                activity.startActivity(intent);
                            }
                        }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Log.i(TAG, "You unlocked a secret unicorn.");
                            }
                        });
                        builder.create().show();
                        Log.e(TAG, "Either no Streaming player for audio was installed, or something important crashed:");
                        e.printStackTrace();
                    }
                }
            }
        });
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) PopupVideoPlayer(org.schabi.newpipe.player.PopupVideoPlayer) InfoItemBuilder(org.schabi.newpipe.info_list.InfoItemBuilder) VideoStream(org.schabi.newpipe.extractor.stream_info.VideoStream) DownloadDialog(org.schabi.newpipe.download.DownloadDialog) Intent(android.content.Intent) Point(android.graphics.Point) AudioStream(org.schabi.newpipe.extractor.stream_info.AudioStream)

Aggregations

VideoStream (org.schabi.newpipe.extractor.stream_info.VideoStream)6 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 Point (android.graphics.Point)2 AlertDialog (android.support.v7.app.AlertDialog)2 Test (org.junit.Test)2 InfoItemBuilder (org.schabi.newpipe.info_list.InfoItemBuilder)2 ExoPlayerActivity (org.schabi.newpipe.player.ExoPlayerActivity)2 Activity (android.app.Activity)1 Bundle (android.os.Bundle)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 ActionBar (android.support.v7.app.ActionBar)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 RecyclerView (android.support.v7.widget.RecyclerView)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 ArrayAdapter (android.widget.ArrayAdapter)1 Button (android.widget.Button)1 ImageView (android.widget.ImageView)1 RelativeLayout (android.widget.RelativeLayout)1