toro icon indicating copy to clipboard operation
toro copied to clipboard

how to Stop Buffering when data is not on wifi

Open sonalpatel22 opened this issue 7 years ago • 4 comments

What kind of issue is this?

  • [ ] Question. If so, declare clearly your target and your current implementation with code formatted in markdown.

  • [ ] Bug report. If so, please supply the way to reproduce the issue, including addition information as follow:

    • [ ] Toro version.
    • [ ] Android version (can be found in Device info). Rooted/Custom rom devices are not supported.
    • [ ] Device name (eg: Nexus 5X, Samsung Galaxy S8)
    • [ ] Source code that can reproduce the issue (a snapshot is expected).
    • [ ] Logcat stack trace in case of fatal issue.
  • [ ] Feature request. Start by telling me what problem you’re trying to solve. Don’t send pull requests to implement new features without first getting my support. Sometimes I leave features out on purpose to keep the project small.

  • [ ] Other. Senseless issues are normally ignored. Please understand and cooperate.

sonalpatel22 avatar Oct 09 '18 06:10 sonalpatel22

/** * Check if there is any connectivity to a Wifi network */ public static boolean isConnectedWifi(Context context){ NetworkInfo info = Connectivity.getNetworkInfo(context); return (info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_WIFI); } //do some other stuffs with boolean response like stop buffering

reshthedev avatar Oct 11 '18 10:10 reshthedev

return (info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_WIFI); } //do some oth I know how to check wifi connectivity I want to answer for " how to stop buffering "

sonalpatel22 avatar Oct 13 '18 11:10 sonalpatel22

@sonalpatel22 Can you share with me your ViewHolder/ToroPlayer implementation?

I think with default helpers, it should just start preparing (= start buffering) when you start the Video. So by default no buffering of not-playing Video I think.

eneim avatar Oct 15 '18 02:10 eneim

    private ExoPlayerViewHelper helper;
    private Uri mediaUri;
    private PlayerView playerView;
    private static final int[] contents = {R.string.license_tos, R.string.license_bbb, R.string.license_cosmos};
    private Activity activity;

    private PostModel livePostModel;
    private OnPlayMediaListener onPlayMediaListener;

    public CompitiotionPlayerViewHolder(Activity act, View itemView, @Nullable PressablePlayerSelector selector, OnPlayMediaListener onPlayMediaListener) {
        super(itemView);
        playerView = (PlayerView) itemView.findViewById(R.id.exoplayer);
        PressablePlayerSelector selector1 = selector;
        this.activity = act;
        if (selector1 != null)
            playerView.setControlDispatcher(new ExoPlayerDispatcher(selector1, this));
        playerView.setControllerShowTimeoutMs(800);
        this.onPlayMediaListener = onPlayMediaListener;
        findViews(itemView);
    }

    public void fullscreen(int position, View view, PostModel PostModel) {
        String content = activity.getString(contents[position % contents.length]);
        Point viewSize = new Point(view.getWidth(), view.getHeight());
        Point videoSize = new Point(view.getWidth(), view.getHeight());
        if (view instanceof PlayerView && ((PlayerView) view).getPlayer() != null) {
            Player player = ((PlayerView) view).getPlayer();
            Format videoFormat = player instanceof SimpleExoPlayer ?  //
                    ((SimpleExoPlayer) player).getVideoFormat() : null;
            if (videoFormat != null
                    && videoFormat.width != Format.NO_VALUE
                    && videoFormat.height != Format.NO_VALUE) {
                videoSize.set(videoFormat.width, videoFormat.height);
            }
        }
        String url = UrlConstant.GALLERY_IMAGE_PREFIX + PostModel.getImage();
        Log.e("uri", "" + url);
        Uri uri = Uri.parse(url);
        Intent intent = createIntent(activity, position, uri, content, this.getCurrentPlaybackInfo(), viewSize, videoSize, true);
//        ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, view, ViewCompat.getTransitionName(view));
        activity.startActivityForResult(intent, RQ_PLAYBACK_INFO, null);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void bind(int position, Object object) {
      
            initFullscreenButton(position, livePostModel);

            final AppCompatImageButton play = playerView.findViewById(R.id.exo_play);
            play.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //when video player one time playing seekbar notautomatically decrease to 0
                    //so..for strat video again
                    if (playerView.getPlayer().getDuration() <= helper.getLatestPlaybackInfo().getResumePosition()) {
                        playerView.getPlayer().seekTo(0);
                    }
                    if (helper != null) helper.play();
                    //For stop other videos which are already playing
                    onPlayMediaListener.onPlayMedia(helper);

                }
            });

            final AppCompatImageButton pause = playerView.findViewById(R.id.exo_pause);
            pause.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (helper.isPlaying()) helper.pause();
                    //FOR Stop again auto playing video if user did pause video for one time
                    //So set value at first pause
                    if (livePostModel.getIsvideoplayautomatically() == PostModel.DEFAULT)
                        livePostModel.setIsvideoplayautomatically(PostModel.FIRSTTIME);


                }
            });
}
        }
    }


    private void initFullscreenButton(final int pos, final PostModel livePostModel) {
        ToroControlView controlView = playerView.findViewById(R.id.exo_controller);

        FrameLayout mFullScreenButton = controlView.findViewById(R.id.exo_fullscreen_button);
        mFullScreenButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                fullscreen(pos, v, livePostModel);
            }
        });
    }


  
    @NonNull
    @Override
    public View getPlayerView() {
        return playerView;
    }

    @NonNull
    @Override
    public PlaybackInfo getCurrentPlaybackInfo() {
        return helper != null ? helper.getLatestPlaybackInfo() : new PlaybackInfo();
    }

    @Override
    public void initialize(@NonNull Container container, @NonNull PlaybackInfo playbackInfo) {
        if (!NetworkUtil.isWifiConnected(activity)) {
            //Its make video not play automatically
            container.setPlayerSelector(null);
        }
        if (helper == null) {
            helper = new ExoPlayerViewHelper(this, mediaUri);
        }
        helper.initialize(container, playbackInfo);
    }

    @Override
    public void play() {
        if (helper != null) helper.play();
        if (livePostModel != null && livePostModel.getIsvideoplayautomatically() == PostModel.FIRSTTIME) {
            //FOR Stop again auto playing video if user did pause video for one time
            helper.pause();
        } else {
            //For stop other VIDEOS OR AUDIOS which are already playing
            onPlayMediaListener.onPlayMedia(helper);
        }
    }

    @Override
    public void pause() {
        if (helper != null)
            helper.pause();
    }

    @Override
    public boolean isPlaying() {
        return helper != null && helper.isPlaying();
    }

    @Override
    public void release() {
        if (helper != null) {
            helper.release();
            helper = null;
        }
    }

    @Override
    public boolean wantsToPlay() {
        return ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= 0.85;
    }

    @Override
    public int getPlayerOrder() {
        return getAdapterPosition();
    }

    @Override
    public String toString() {
        return "ExoPlayer{" + hashCode() + " " + getAdapterPosition() + "}";
    }
}

sonalpatel22 avatar Oct 15 '18 04:10 sonalpatel22