DetailPlayer.java 6.0 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.shuyu.gsyvideoplayer.GSYPreViewManager;
S
shuyu 已提交
14
import com.shuyu.gsyvideoplayer.GSYVideoPlayer;
S
shuyu 已提交
15

S
shuyu 已提交
16
import com.shuyu.gsyvideoplayer.utils.OrientationUtils;
S
shuyu 已提交
17
import com.shuyu.gsyvideoplayer.video.CustomGSYVideoPlayer;
S
shuyu 已提交
18
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
S
shuyu 已提交
19

S
shuyu 已提交
20 21 22 23 24

import butterknife.BindView;
import butterknife.ButterKnife;


S
shuyu 已提交
25
public class DetailPlayer extends AppCompatActivity {
S
shuyu 已提交
26 27 28 29

    @BindView(R.id.post_detail_nested_scroll)
    NestedScrollView postDetailNestedScroll;
    @BindView(R.id.detail_player)
S
shuyu 已提交
30
    CustomGSYVideoPlayer detailPlayer;
S
shuyu 已提交
31 32 33
    @BindView(R.id.activity_detail_player)
    RelativeLayout activityDetailPlayer;

S
1.3.6  
shuyu 已提交
34
    private boolean isPlay;
S
shuyu 已提交
35
    private boolean isPause;
S
shuyu 已提交
36 37 38 39 40 41 42 43 44

    private OrientationUtils orientationUtils;

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

S
shuyu 已提交
45 46 47
        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";
        detailPlayer.setUp(url, true, null, "测试视频");
S
shuyu 已提交
48 49 50 51 52 53 54 55 56 57

        //增加封面
        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);
S
1.3.6  
shuyu 已提交
58
        //初始化不打开外部的旋转
S
shuyu 已提交
59 60
        orientationUtils.setEnable(false);

S
1.1.4  
shuyu 已提交
61
        detailPlayer.setIsTouchWiget(true);
S
1.3.6  
shuyu 已提交
62 63 64
        //打开自动旋转
        detailPlayer.setRotateViewAuto(true);
        detailPlayer.setLockLand(false);
S
1.3.2  
shuyu 已提交
65 66
        detailPlayer.setShowFullAnimation(false);

S
shuyu 已提交
67 68 69
        detailPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
S
1.3.6  
shuyu 已提交
70 71 72
                //直接横屏
                orientationUtils.resolveByClick();

S
1.3.2  
shuyu 已提交
73 74
                //第一个true是否需要隐藏actionbar,第二个true是否需要隐藏statusbar
                detailPlayer.startWindowFullscreen(DetailPlayer.this, true, true);
S
shuyu 已提交
75 76 77
            }
        });

S
1.3.6  
shuyu 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
        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);
            }
S
shuyu 已提交
96 97 98 99 100 101 102 103

            @Override
            public void onQuitFullscreen(String url, Object... objects) {
                super.onQuitFullscreen(url, objects);
                if (orientationUtils != null) {
                    orientationUtils.backToProtVideo();
                }
            }
S
1.3.6  
shuyu 已提交
104 105
        });

106 107 108 109 110 111 112
        detailPlayer.setBottomProgressBarDrawable(getResources().getDrawable(R.drawable.video_new_progress));
        detailPlayer.setDialogVolumeProgressBar(getResources().getDrawable(R.drawable.video_new_volume_progress_bg));
        detailPlayer.setDialogProgressBar(getResources().getDrawable(R.drawable.video_new_progress));
        detailPlayer.setBottomShowProgressBarDrawable(getResources().getDrawable(R.drawable.video_new_seekbar_progress),
        getResources().getDrawable(R.drawable.video_new_seekbar_thumb));
        detailPlayer.setDialogProgressColor(getResources().getColor(R.color.colorAccent), -11);

S
shuyu 已提交
113 114 115 116
    }

    @Override
    public void onBackPressed() {
117 118 119 120 121

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

S
1.3.3  
shuyu 已提交
122
        if (StandardGSYVideoPlayer.backFromWindowFull(this)) {
S
shuyu 已提交
123 124 125 126 127
            return;
        }
        super.onBackPressed();
    }

S
shuyu 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140

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

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

S
shuyu 已提交
141 142 143 144
    @Override
    protected void onDestroy() {
        super.onDestroy();
        GSYVideoPlayer.releaseAllVideos();
S
shuyu 已提交
145
        GSYPreViewManager.instance().releaseMediaPlayer();
S
1.3.3  
shuyu 已提交
146 147
        if (orientationUtils != null)
            orientationUtils.releaseListener();
S
shuyu 已提交
148 149
    }

S
1.3.6  
shuyu 已提交
150 151 152 153
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        //如果旋转了就全屏
S
shuyu 已提交
154
        if (isPlay && !isPause) {
S
1.3.6  
shuyu 已提交
155 156 157 158 159 160 161 162 163 164 165 166 167
            if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_USER) {
                if (!detailPlayer.isIfCurrentIsFullscreen()) {
                    detailPlayer.startWindowFullscreen(DetailPlayer.this, true, true);
                }
            } else {
                //新版本isIfCurrentIsFullscreen的标志位内部提前设置了,所以不会和手动点击冲突
                if (detailPlayer.isIfCurrentIsFullscreen()) {
                    StandardGSYVideoPlayer.backFromWindowFull(this);
                }
            }
        }
    }

S
shuyu 已提交
168 169 170 171 172 173 174 175 176

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

}