DetailPlayer.java 8.8 KB
Newer Older
S
shuyu 已提交
1 2
package com.example.gsyvideoplayer;

S
1.3.6  
shuyu 已提交
3 4
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
S
shuyu 已提交
5 6 7 8 9 10 11
import android.os.Bundle;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

S
1.3.6  
shuyu 已提交
12
import com.example.gsyvideoplayer.listener.SampleListener;
S
shuyu 已提交
13
import com.example.gsyvideoplayer.video.LandLayoutVideo;
S
shuyu 已提交
14
import com.shuyu.gsyvideoplayer.GSYPreViewManager;
S
shuyu 已提交
15
import com.shuyu.gsyvideoplayer.GSYVideoManager;
S
shuyu 已提交
16
import com.shuyu.gsyvideoplayer.GSYVideoPlayer;
S
shuyu 已提交
17

18
import com.shuyu.gsyvideoplayer.builder.GSYVideoBuilder;
19
import com.shuyu.gsyvideoplayer.listener.LockClickListener;
S
shuyu 已提交
20
import com.shuyu.gsyvideoplayer.model.VideoOptionModel;
21
import com.shuyu.gsyvideoplayer.utils.Debuger;
S
shuyu 已提交
22 23
import com.shuyu.gsyvideoplayer.utils.OrientationUtils;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
S
shuyu 已提交
24

S
shuyu 已提交
25

S
shuyu 已提交
26 27 28
import java.util.ArrayList;
import java.util.List;

S
shuyu 已提交
29 30
import butterknife.BindView;
import butterknife.ButterKnife;
S
shuyu 已提交
31
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
S
shuyu 已提交
32 33


S
shuyu 已提交
34
public class DetailPlayer extends AppCompatActivity {
S
shuyu 已提交
35 36 37

    @BindView(R.id.post_detail_nested_scroll)
    NestedScrollView postDetailNestedScroll;
S
shuyu 已提交
38 39 40

    //推荐使用StandardGSYVideoPlayer,功能一致
    //CustomGSYVideoPlayer部分功能处于试验阶段
S
shuyu 已提交
41
    @BindView(R.id.detail_player)
S
shuyu 已提交
42
    LandLayoutVideo detailPlayer;
S
shuyu 已提交
43

S
shuyu 已提交
44 45 46
    @BindView(R.id.activity_detail_player)
    RelativeLayout activityDetailPlayer;

S
1.3.6  
shuyu 已提交
47
    private boolean isPlay;
S
shuyu 已提交
48
    private boolean isPause;
S
shuyu 已提交
49 50 51 52 53 54 55 56 57

    private OrientationUtils orientationUtils;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail_player);
        ButterKnife.bind(this);

S
shuyu 已提交
58

S
shuyu 已提交
59
        String url = "http://baobab.wdjcdn.com/14564977406580.mp4";
60 61

        //String url = "http://hcjs2ra2rytd8v8np1q.exp.bcevod.com/mda-hegtjx8n5e8jt9zv/mda-hegtjx8n5e8jt9zv.m3u8";
S
shuyu 已提交
62
        //String url = "http://7xse1z.com1.z0.glb.clouddn.com/1491813192";
S
shuyu 已提交
63
        //String url = "http://ocgk7i2aj.bkt.clouddn.com/17651ac2-693c-47e9-b2d2-b731571bad37";
S
shuyu 已提交
64
        //String url = "http://111.198.24.133:83/yyy_login_server/pic/YB059284/97778276040859/1.mp4";
S
shuyu 已提交
65
        //String url = "http://vr.tudou.com/v2proxy/v?sid=95001&id=496378919&st=3&pw=";
66
        //String url = "http://pl-ali.youku.com/playlist/m3u8?type=mp4&ts=1490185963&keyframe=0&vid=XMjYxOTQ1Mzg2MA==&ep=ciadGkiFU8cF4SvajD8bYyuwJiYHXJZ3rHbN%2FrYDAcZuH%2BrC6DPcqJ21TPs%3D&sid=04901859548541247bba8&token=0524&ctype=12&ev=1&oip=976319194";
S
shuyu 已提交
67
        //String url = "http://hls.ciguang.tv/hdtv/video.m3u8";
S
shuyu 已提交
68
        //String url = "https://res.exexm.com/cw_145225549855002";
69
        //detailPlayer.setUp(url, false, null, "测试视频");
70 71
        //detailPlayer.setLooping(true);
        //detailPlayer.setShowPauseCover(false);
S
shuyu 已提交
72
        /*VideoOptionModel videoOptionModel =
73
                new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", 5);
S
shuyu 已提交
74 75 76 77
        List<VideoOptionModel> list = new ArrayList<>();
        list.add(videoOptionModel);
        GSYVideoManager.instance().setOptionModelList(list);*/

78
        //GSYVideoManager.instance().setTimeOut(4000, true);
S
shuyu 已提交
79

S
shuyu 已提交
80 81 82 83
        //增加封面
        ImageView imageView = new ImageView(this);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setImageResource(R.mipmap.xxx1);
84 85

        //detailPlayer.setThumbImageView(imageView);
S
shuyu 已提交
86 87 88

        resolveNormalVideoUI();

89
        //外部辅助的旋转,帮助全屏
S
shuyu 已提交
90
        orientationUtils = new OrientationUtils(this, detailPlayer);
S
1.3.6  
shuyu 已提交
91
        //初始化不打开外部的旋转
S
shuyu 已提交
92 93
        orientationUtils.setEnable(false);

94 95 96 97 98 99 100 101 102
        GSYVideoBuilder gsyVideoBuilder = new GSYVideoBuilder();
        gsyVideoBuilder.setThumbImageView(imageView)
                .setIsTouchWiget(true)
                .setRotateViewAuto(false)
                .setLockLand(false)
                .setShowFullAnimation(false)
                .setNeedLockFull(true)
                .setSeekRatio(1)
                .setUrl(url)
S
shuyu 已提交
103
                .setCacheWithPlay(false)
104 105 106 107
                .setVideoTitle("测试视频")
                .setStandardVideoAllCallBack(new SampleListener() {
                    @Override
                    public void onPrepared(String url, Object... objects) {
108 109
                        Debuger.printfError("***** onPrepared **** " + objects[0]);
                        Debuger.printfError("***** onPrepared **** " + objects[1]);
110 111 112 113 114 115
                        super.onPrepared(url, objects);
                        //开始播放了才能旋转和全屏
                        orientationUtils.setEnable(true);
                        isPlay = true;
                    }

116 117 118 119 120 121 122
                    @Override
                    public void onEnterFullscreen(String url, Object... objects) {
                        super.onEnterFullscreen(url, objects);
                        Debuger.printfError("***** onEnterFullscreen **** " + objects[0]);//title
                        Debuger.printfError("***** onEnterFullscreen **** " + objects[1]);//当前全屏player
                    }

123 124 125 126 127 128 129 130 131 132 133 134 135
                    @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);
136 137
                        Debuger.printfError("***** onQuitFullscreen **** " + objects[0]);//title
                        Debuger.printfError("***** onQuitFullscreen **** " + objects[1]);//当前非全屏player
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
                        if (orientationUtils != null) {
                            orientationUtils.backToProtVideo();
                        }
                    }
                })
                .setLockClickListener(new LockClickListener() {
                    @Override
                    public void onClick(View view, boolean lock) {
                        if (orientationUtils != null) {
                            //配合下方的onConfigurationChanged
                            orientationUtils.setEnable(!lock);
                        }
                    }
                }).build(detailPlayer);

S
shuyu 已提交
153 154 155
        detailPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
S
1.3.6  
shuyu 已提交
156 157 158
                //直接横屏
                orientationUtils.resolveByClick();

S
1.3.2  
shuyu 已提交
159 160
                //第一个true是否需要隐藏actionbar,第二个true是否需要隐藏statusbar
                detailPlayer.startWindowFullscreen(DetailPlayer.this, true, true);
S
shuyu 已提交
161 162 163 164 165 166 167
            }
        });

    }

    @Override
    public void onBackPressed() {
168 169 170 171 172

        if (orientationUtils != null) {
            orientationUtils.backToProtVideo();
        }

S
1.3.3  
shuyu 已提交
173
        if (StandardGSYVideoPlayer.backFromWindowFull(this)) {
S
shuyu 已提交
174 175 176 177 178
            return;
        }
        super.onBackPressed();
    }

S
shuyu 已提交
179 180 181 182 183 184 185 186 187 188 189 190 191

    @Override
    protected void onPause() {
        super.onPause();
        isPause = true;
    }

    @Override
    protected void onResume() {
        super.onResume();
        isPause = false;
    }

S
shuyu 已提交
192 193 194 195
    @Override
    protected void onDestroy() {
        super.onDestroy();
        GSYVideoPlayer.releaseAllVideos();
S
shuyu 已提交
196
        //GSYPreViewManager.instance().releaseMediaPlayer();
S
1.3.3  
shuyu 已提交
197 198
        if (orientationUtils != null)
            orientationUtils.releaseListener();
S
shuyu 已提交
199 200
    }

S
1.3.6  
shuyu 已提交
201 202 203 204
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        //如果旋转了就全屏
S
shuyu 已提交
205
        if (isPlay && !isPause) {
S
1.3.6  
shuyu 已提交
206 207 208 209 210 211 212 213 214
            if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_USER) {
                if (!detailPlayer.isIfCurrentIsFullscreen()) {
                    detailPlayer.startWindowFullscreen(DetailPlayer.this, true, true);
                }
            } else {
                //新版本isIfCurrentIsFullscreen的标志位内部提前设置了,所以不会和手动点击冲突
                if (detailPlayer.isIfCurrentIsFullscreen()) {
                    StandardGSYVideoPlayer.backFromWindowFull(this);
                }
215 216 217
                if (orientationUtils != null) {
                    orientationUtils.setEnable(true);
                }
S
1.3.6  
shuyu 已提交
218 219 220 221
            }
        }
    }

S
shuyu 已提交
222 223 224 225 226 227 228 229 230

    private void resolveNormalVideoUI() {
        //增加title
        detailPlayer.getTitleTextView().setVisibility(View.GONE);
        detailPlayer.getTitleTextView().setText("测试视频");
        detailPlayer.getBackButton().setVisibility(View.GONE);
    }

}