Search in sources :

Example 6 with SampleListener

use of com.example.gsyvideoplayer.listener.SampleListener in project GSYVideoPlayer by CarGuo.

the class RecyclerItemNormalHolder method onBind.

public void onBind(final int position, VideoModel videoModel) {
    //增加封面
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    if (position % 2 == 0) {
        imageView.setImageResource(R.mipmap.xxx1);
    } else {
        imageView.setImageResource(R.mipmap.xxx2);
    }
    if (imageView.getParent() != null) {
        ViewGroup viewGroup = (ViewGroup) imageView.getParent();
        viewGroup.removeView(imageView);
    }
    gsyVideoPlayer.setThumbImageView(imageView);
    final String url = "http://baobab.wdjcdn.com/14564977406580.mp4";
    //默认缓存路径
    gsyVideoPlayer.setUp(url, true, null, "这是title");
    //增加title
    gsyVideoPlayer.getTitleTextView().setVisibility(View.GONE);
    //设置返回键
    gsyVideoPlayer.getBackButton().setVisibility(View.GONE);
    //设置全屏按键功能
    gsyVideoPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            resolveFullBtn(gsyVideoPlayer);
        }
    });
    gsyVideoPlayer.setRotateViewAuto(true);
    gsyVideoPlayer.setLockLand(true);
    gsyVideoPlayer.setPlayTag(TAG);
    gsyVideoPlayer.setShowFullAnimation(true);
    //循环
    //gsyVideoPlayer.setLooping(true);
    gsyVideoPlayer.setNeedLockFull(true);
    //gsyVideoPlayer.setSpeed(2);
    gsyVideoPlayer.setPlayPosition(position);
    gsyVideoPlayer.setStandardVideoAllCallBack(new SampleListener() {

        @Override
        public void onPrepared(String url, Object... objects) {
            super.onPrepared(url, objects);
            Debuger.printfLog("onPrepared");
            if (!gsyVideoPlayer.isIfCurrentIsFullscreen()) {
                //静音
                GSYVideoManager.instance().setNeedMute(true);
            }
        }

        @Override
        public void onQuitFullscreen(String url, Object... objects) {
            super.onQuitFullscreen(url, objects);
            //全屏不静音
            GSYVideoManager.instance().setNeedMute(true);
        }

        @Override
        public void onEnterFullscreen(String url, Object... objects) {
            super.onEnterFullscreen(url, objects);
            GSYVideoManager.instance().setNeedMute(false);
        }
    });
}
Also used : ViewGroup(android.view.ViewGroup) SampleListener(com.example.gsyvideoplayer.listener.SampleListener) ImageView(android.widget.ImageView) View(android.view.View) BindView(butterknife.BindView)

Example 7 with SampleListener

use of com.example.gsyvideoplayer.listener.SampleListener in project GSYVideoPlayer by CarGuo.

the class DetailPlayer method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail_player);
    ButterKnife.bind(this);
    String url = "http://baobab.wdjcdn.com/14564977406580.mp4";
    //String url = "https://res.exexm.com/cw_145225549855002";
    detailPlayer.setUp(url, true, null, "测试视频");
    /*VideoOptionModel videoOptionModel =
                new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", 50);
        List<VideoOptionModel> list = new ArrayList<>();
        list.add(videoOptionModel);
        GSYVideoManager.instance().setOptionModelList(list);*/
    //增加封面
    ImageView imageView = new ImageView(this);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setImageResource(R.mipmap.xxx1);
    detailPlayer.setThumbImageView(imageView);
    resolveNormalVideoUI();
    //外部辅助的旋转,帮助全屏
    orientationUtils = new OrientationUtils(this, detailPlayer);
    //初始化不打开外部的旋转
    orientationUtils.setEnable(false);
    detailPlayer.setIsTouchWiget(true);
    //关闭自动旋转
    detailPlayer.setRotateViewAuto(false);
    detailPlayer.setLockLand(false);
    detailPlayer.setShowFullAnimation(false);
    detailPlayer.setNeedLockFull(true);
    detailPlayer.setOpenPreView(true);
    detailPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            //直接横屏
            orientationUtils.resolveByClick();
            //第一个true是否需要隐藏actionbar,第二个true是否需要隐藏statusbar
            detailPlayer.startWindowFullscreen(DetailPlayer.this, true, true);
        }
    });
    detailPlayer.setStandardVideoAllCallBack(new SampleListener() {

        @Override
        public void onPrepared(String url, Object... objects) {
            super.onPrepared(url, objects);
            //开始播放了才能旋转和全屏
            orientationUtils.setEnable(true);
            isPlay = true;
        }

        @Override
        public void onAutoComplete(String url, Object... objects) {
            super.onAutoComplete(url, objects);
        }

        @Override
        public void onClickStartError(String url, Object... objects) {
            super.onClickStartError(url, objects);
        }

        @Override
        public void onQuitFullscreen(String url, Object... objects) {
            super.onQuitFullscreen(url, objects);
            if (orientationUtils != null) {
                orientationUtils.backToProtVideo();
            }
        }
    });
    detailPlayer.setLockClickListener(new LockClickListener() {

        @Override
        public void onClick(View view, boolean lock) {
            if (orientationUtils != null) {
                //配合下方的onConfigurationChanged
                orientationUtils.setEnable(!lock);
            }
        }
    });
}
Also used : OrientationUtils(com.shuyu.gsyvideoplayer.utils.OrientationUtils) ImageView(android.widget.ImageView) SampleListener(com.example.gsyvideoplayer.listener.SampleListener) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) LockClickListener(com.shuyu.gsyvideoplayer.listener.LockClickListener)

Example 8 with SampleListener

use of com.example.gsyvideoplayer.listener.SampleListener in project GSYVideoPlayer by CarGuo.

the class ListVideo2Activity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    // 设置一个exit transition
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
        getWindow().setEnterTransition(new Explode());
        getWindow().setExitTransition(new Explode());
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list_video2);
    ButterKnife.bind(this);
    listVideoUtil = new ListVideoUtil(this);
    listVideoUtil.setFullViewContainer(videoFullContainer);
    listVideoUtil.setHideStatusBar(true);
    //listVideoUtil.setHideActionBar(true);
    listVideoUtil.setNeedLockFull(true);
    listVideoAdapter = new ListVideoAdapter(this, listVideoUtil);
    listVideoAdapter.setRootView(activityListVideo);
    videoList.setAdapter(listVideoAdapter);
    //listVideoUtil.setShowFullAnimation(true);
    //listVideoUtil.setAutoRotation(true);
    //listVideoUtil.setFullLandFrist(true);
    videoList.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            ListVideo2Activity.this.firstVisibleItem = firstVisibleItem;
            lastVisibleItem = firstVisibleItem + visibleItemCount;
            //大于0说明有播放,//对应的播放列表TAG
            if (listVideoUtil.getPlayPosition() >= 0 && listVideoUtil.getPlayTAG().equals(ListVideoAdapter.TAG)) {
                //当前播放的位置
                int position = listVideoUtil.getPlayPosition();
                //不可视的是时候
                if ((position < firstVisibleItem || position > lastVisibleItem)) {
                    //如果是小窗口就不需要处理
                    if (!listVideoUtil.isSmall()) {
                        //小窗口
                        int size = CommonUtil.dip2px(ListVideo2Activity.this, 150);
                        listVideoUtil.showSmallVideo(new Point(size, size), false, true);
                    }
                } else {
                    if (listVideoUtil.isSmall()) {
                        listVideoUtil.smallVideoToNormal();
                    }
                }
            }
        }
    });
    //小窗口关闭被点击的时候回调处理回复页面
    listVideoUtil.setVideoAllCallBack(new SampleListener() {

        @Override
        public void onPrepared(String url, Object... objects) {
            super.onPrepared(url, objects);
            Debuger.printfLog("Duration " + listVideoUtil.getDuration() + " CurrentPosition " + listVideoUtil.getCurrentPositionWhenPlaying());
        }

        @Override
        public void onQuitSmallWidget(String url, Object... objects) {
            super.onQuitSmallWidget(url, objects);
            //大于0说明有播放,//对应的播放列表TAG
            if (listVideoUtil.getPlayPosition() >= 0 && listVideoUtil.getPlayTAG().equals(ListVideoAdapter.TAG)) {
                //当前播放的位置
                int position = listVideoUtil.getPlayPosition();
                //不可视的是时候
                if ((position < firstVisibleItem || position > lastVisibleItem)) {
                    //释放掉视频
                    listVideoUtil.releaseVideoPlayer();
                    listVideoAdapter.notifyDataSetChanged();
                }
            }
        }
    });
}
Also used : Explode(android.transition.Explode) ListVideoUtil(com.shuyu.gsyvideoplayer.utils.ListVideoUtil) AbsListView(android.widget.AbsListView) Point(android.graphics.Point) SampleListener(com.example.gsyvideoplayer.listener.SampleListener) ListVideoAdapter(com.example.gsyvideoplayer.adapter.ListVideoAdapter) Point(android.graphics.Point)

Aggregations

SampleListener (com.example.gsyvideoplayer.listener.SampleListener)8 View (android.view.View)6 ImageView (android.widget.ImageView)6 BindView (butterknife.BindView)5 NestedScrollView (android.support.v4.widget.NestedScrollView)4 LockClickListener (com.shuyu.gsyvideoplayer.listener.LockClickListener)4 OrientationUtils (com.shuyu.gsyvideoplayer.utils.OrientationUtils)4 Point (android.graphics.Point)3 Explode (android.transition.Explode)2 ViewGroup (android.view.ViewGroup)2 RecyclerView (android.support.v7.widget.RecyclerView)1 WebSettings (android.webkit.WebSettings)1 AbsListView (android.widget.AbsListView)1 ListVideoAdapter (com.example.gsyvideoplayer.adapter.ListVideoAdapter)1 ScrollWebView (com.example.gsyvideoplayer.view.ScrollWebView)1 GSYVideoModel (com.shuyu.gsyvideoplayer.model.GSYVideoModel)1 ListVideoUtil (com.shuyu.gsyvideoplayer.utils.ListVideoUtil)1 ArrayList (java.util.ArrayList)1