Search in sources :

Example 1 with SampleListener

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

the class DanmkuVideoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_danmaku_layout);
    ButterKnife.bind(this);
    //使用自定义的全屏切换图片,!!!注意xml布局中也需要设置为一样的
    //必须在setUp之前设置
    danmakuVideoPlayer.setShrinkImageRes(R.drawable.custom_shrink);
    danmakuVideoPlayer.setEnlargeImageRes(R.drawable.custom_enlarge);
    String url = "http://baobab.wdjcdn.com/14564977406580.mp4";
    //String url = "https://res.exexm.com/cw_145225549855002";
    danmakuVideoPlayer.setUp(url, true, null, "测试视频");
    //增加封面
    ImageView imageView = new ImageView(this);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setImageResource(R.mipmap.xxx1);
    danmakuVideoPlayer.setThumbImageView(imageView);
    resolveNormalVideoUI();
    //外部辅助的旋转,帮助全屏
    orientationUtils = new OrientationUtils(this, danmakuVideoPlayer);
    //初始化不打开外部的旋转
    orientationUtils.setEnable(false);
    danmakuVideoPlayer.setIsTouchWiget(true);
    //关闭自动旋转
    danmakuVideoPlayer.setRotateViewAuto(false);
    danmakuVideoPlayer.setLockLand(false);
    danmakuVideoPlayer.setShowFullAnimation(false);
    danmakuVideoPlayer.setNeedLockFull(true);
    //detailPlayer.setOpenPreView(true);
    danmakuVideoPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            //直接横屏
            orientationUtils.resolveByClick();
            //第一个true是否需要隐藏actionbar,第二个true是否需要隐藏statusbar
            danmakuVideoPlayer.startWindowFullscreen(DanmkuVideoActivity.this, true, true);
        }
    });
    danmakuVideoPlayer.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();
            }
        }
    });
    danmakuVideoPlayer.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 2 with SampleListener

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

the class DetailListPlayer method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_deatil_list_player);
    ButterKnife.bind(this);
    //String url = "http://baobab.wd jcdn.com/14564977406580.mp4";
    List<GSYVideoModel> urls = new ArrayList<>();
    urls.add(new GSYVideoModel("http://baobab.wdjcdn.com/14564977406580.mp4", "标题1"));
    urls.add(new GSYVideoModel("http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4", "标题2"));
    urls.add(new GSYVideoModel("http://baobab.wdjcdn.com/14564977406580.mp4", "标题3"));
    urls.add(new GSYVideoModel("http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4", "标题4"));
    detailPlayer.setUp(urls, true, 0, "");
    //增加封面
    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.getFullscreenButton().setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            //直接横屏
            orientationUtils.resolveByClick();
            //第一个true是否需要隐藏actionbar,第二个true是否需要隐藏statusbar
            detailPlayer.startWindowFullscreen(DetailListPlayer.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 : ArrayList(java.util.ArrayList) 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) GSYVideoModel(com.shuyu.gsyvideoplayer.model.GSYVideoModel) OrientationUtils(com.shuyu.gsyvideoplayer.utils.OrientationUtils) ImageView(android.widget.ImageView)

Example 3 with SampleListener

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

the class RecyclerView2Activity 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_recycler_view2);
    ButterKnife.bind(this);
    initView();
    listVideoUtil.setHideActionBar(true);
    //listVideoUtil.setShowFullAnimation(true);
    //listVideoUtil.setAutoRotation(true);
    //listVideoUtil.setFullLandFrist(true);
    listItemRecycler.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            firstVisibleItem = linearLayoutManager.findFirstVisibleItemPosition();
            lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
            Debuger.printfLog("firstVisibleItem " + firstVisibleItem + " lastVisibleItem " + lastVisibleItem);
            //大于0说明有播放,//对应的播放列表TAG
            if (listVideoUtil.getPlayPosition() >= 0 && listVideoUtil.getPlayTAG().equals(RecyclerItemViewHolder.TAG)) {
                //当前播放的位置
                int position = listVideoUtil.getPlayPosition();
                //不可视的是时候
                if ((position < firstVisibleItem || position > lastVisibleItem)) {
                    //如果是小窗口就不需要处理
                    if (!listVideoUtil.isSmall() && !listVideoUtil.isFull()) {
                        //小窗口
                        int size = CommonUtil.dip2px(RecyclerView2Activity.this, 150);
                        //actionbar为true才不会掉下面去
                        listVideoUtil.showSmallVideo(new Point(size, size), true, 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();
                    recyclerBaseAdapter.notifyDataSetChanged();
                }
            }
        }
    });
}
Also used : Explode(android.transition.Explode) RecyclerView(android.support.v7.widget.RecyclerView) Point(android.graphics.Point) SampleListener(com.example.gsyvideoplayer.listener.SampleListener) Point(android.graphics.Point)

Example 4 with SampleListener

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

the class WebDetailActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web_detail);
    ButterKnife.bind(this);
    String url = "http://baobab.wdjcdn.com/14564977406580.mp4";
    //String url = "https://d131x7vzzf85jg.cloudfront.net/upload/documents/paper/b2/61/00/00/20160420_115018_b544.mp4";
    webPlayer.setUp(url, true, null, "测试视频");
    //增加封面
    ImageView imageView = new ImageView(this);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setImageResource(R.mipmap.xxx1);
    webPlayer.setThumbImageView(imageView);
    resolveNormalVideoUI();
    //外部辅助的旋转,帮助全屏
    orientationUtils = new OrientationUtils(this, webPlayer);
    //初始化不打开外部的旋转
    orientationUtils.setEnable(false);
    webPlayer.setIsTouchWiget(true);
    //关闭自动旋转
    webPlayer.setRotateViewAuto(false);
    webPlayer.setLockLand(false);
    webPlayer.setShowFullAnimation(false);
    webPlayer.setNeedLockFull(true);
    //detailPlayer.setOpenPreView(true);
    webPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            //直接横屏
            orientationUtils.resolveByClick();
            //第一个true是否需要隐藏actionbar,第二个true是否需要隐藏statusbar
            webPlayer.startWindowFullscreen(WebDetailActivity.this, true, true);
        }
    });
    webPlayer.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();
            }
        }
    });
    webPlayer.setLockClickListener(new LockClickListener() {

        @Override
        public void onClick(View view, boolean lock) {
            if (orientationUtils != null) {
                //配合下方的onConfigurationChanged
                orientationUtils.setEnable(!lock);
            }
        }
    });
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    webView.loadUrl("https://www.baidu.com");
    webTopLayout.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {

        @Override
        public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            if (!webPlayer.isIfCurrentIsFullscreen() && scrollY >= 0 && isPlay) {
                if (scrollY > webPlayer.getHeight()) {
                    //如果是小窗口就不需要处理
                    if (!isSamll) {
                        isSamll = true;
                        int size = CommonUtil.dip2px(WebDetailActivity.this, 150);
                        webPlayer.showSmallVideo(new Point(size, size), true, true);
                        orientationUtils.setEnable(false);
                    }
                } else {
                    if (isSamll) {
                        isSamll = false;
                        orientationUtils.setEnable(true);
                        //必须
                        webTopLayoutVideo.postDelayed(new Runnable() {

                            @Override
                            public void run() {
                                webPlayer.hideSmallVideo();
                            }
                        }, 50);
                    }
                }
                webTopLayoutVideo.setTranslationY((scrollY <= webTopLayoutVideo.getHeight()) ? -scrollY : -webTopLayoutVideo.getHeight());
            }
        }
    });
}
Also used : Point(android.graphics.Point) SampleListener(com.example.gsyvideoplayer.listener.SampleListener) ImageView(android.widget.ImageView) BindView(butterknife.BindView) ScrollWebView(com.example.gsyvideoplayer.view.ScrollWebView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) LockClickListener(com.shuyu.gsyvideoplayer.listener.LockClickListener) Point(android.graphics.Point) WebSettings(android.webkit.WebSettings) OrientationUtils(com.shuyu.gsyvideoplayer.utils.OrientationUtils) ImageView(android.widget.ImageView) NestedScrollView(android.support.v4.widget.NestedScrollView)

Example 5 with SampleListener

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

the class ListNormalAdapter method getView.

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    final ViewHolder holder;
    if (convertView == null) {
        holder = new ViewHolder();
        convertView = inflater.inflate(R.layout.list_video_item_normal, null);
        holder.gsyVideoPlayer = (StandardGSYVideoPlayer) convertView.findViewById(R.id.video_item_player);
        holder.imageView = new ImageView(context);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    //增加封面
    holder.imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    if (position % 2 == 0) {
        holder.imageView.setImageResource(R.mipmap.xxx1);
    } else {
        holder.imageView.setImageResource(R.mipmap.xxx2);
    }
    if (holder.imageView.getParent() != null) {
        ViewGroup viewGroup = (ViewGroup) holder.imageView.getParent();
        viewGroup.removeView(holder.imageView);
    }
    holder.gsyVideoPlayer.setThumbImageView(holder.imageView);
    final String url = "http://baobab.wdjcdn.com/14564977406580.mp4";
    //默认缓存路径
    holder.gsyVideoPlayer.setUp(url, true, null, "这是title");
    //holder.gsyVideoPlayer.setNeedShowWifiTip(false);
    /************************下方为其他路径************************************/
    //如果一个列表的缓存路劲都一一致
    //holder.gsyVideoPlayer.setUp(url, true, new File(FileUtils.getTestPath(), ""));
    /************************下方为其他路径************************************/
    //如果一个列表里的缓存路劲不一致
    //int playPosition = GSYVideoManager.instance().getPlayPosition();
    //避免全屏返回的时候不可用了
    /*if (playPosition < 0 || playPosition != position ||
                !GSYVideoManager.instance().getPlayTag().equals(ListNormalAdapter.TAG)) {
            holder.gsyVideoPlayer.initUIState();
        }*/
    //如果设置了点击封面可以播放,如果缓存列表路径不一致,还需要设置封面点击
    /*holder.gsyVideoPlayer.setThumbPlay(true);

        holder.gsyVideoPlayer.getStartButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //需要切换缓存路径的
                holder.gsyVideoPlayer.setUp(url, true, new File(FileUtils.getTestPath(), ""));
                holder.gsyVideoPlayer.startPlayLogic();
            }
        });

        holder.gsyVideoPlayer.getThumbImageViewLayout().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //需要切换缓存路径的
                holder.gsyVideoPlayer.setUp(url, true, new File(FileUtils.getTestPath(), ""));
                holder.gsyVideoPlayer.startPlayLogic();
            }
        });*/
    //增加title
    holder.gsyVideoPlayer.getTitleTextView().setVisibility(View.GONE);
    //设置返回键
    holder.gsyVideoPlayer.getBackButton().setVisibility(View.GONE);
    //设置全屏按键功能
    holder.gsyVideoPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {

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

        @Override
        public void onPrepared(String url, Object... objects) {
            super.onPrepared(url, objects);
            Debuger.printfLog("onPrepared");
            if (!holder.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);
        }
    });
    return convertView;
}
Also used : ViewGroup(android.view.ViewGroup) ImageView(android.widget.ImageView) SampleListener(com.example.gsyvideoplayer.listener.SampleListener) ImageView(android.widget.ImageView) View(android.view.View)

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