forked from CarGuo/GSYVideoPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleDetailActivityMode2.java
161 lines (136 loc) · 5.71 KB
/
SimpleDetailActivityMode2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package com.example.gsyvideoplayer.simple;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.example.gsyvideoplayer.R;
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder;
import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack;
import com.shuyu.gsyvideoplayer.listener.LockClickListener;
import com.shuyu.gsyvideoplayer.utils.OrientationUtils;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
/**
* 简单详情实现模式2
* 横屏不旋转的 Demo
*/
public class SimpleDetailActivityMode2 extends AppCompatActivity {
StandardGSYVideoPlayer detailPlayer;
private boolean isPlay;
private boolean isPause;
//private OrientationUtils orientationUtils;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_simple_detail_player);
detailPlayer = (StandardGSYVideoPlayer) findViewById(R.id.detail_player);
String url = "http://7xjmzj.com1.z0.glb.clouddn.com/20171026175005_JObCxCE2.mp4";
//增加封面
ImageView imageView = new ImageView(this);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageResource(R.mipmap.xxx1);
//增加title
detailPlayer.getTitleTextView().setVisibility(View.GONE);
detailPlayer.getBackButton().setVisibility(View.GONE);
//外部辅助的旋转,帮助全屏
//orientationUtils = new OrientationUtils(this, detailPlayer);
//初始化不打开外部的旋转
// orientationUtils.setEnable(false);
GSYVideoOptionBuilder gsyVideoOption = new GSYVideoOptionBuilder();
gsyVideoOption.setThumbImageView(imageView)
.setIsTouchWiget(true)
.setRotateViewAuto(false)
.setLockLand(false)
.setAutoFullWithSize(false)
.setShowFullAnimation(false)
.setNeedLockFull(true)
.setUrl(url)
.setCacheWithPlay(false)
.setVideoTitle("测试视频")
///不需要旋转
.setNeedOrientationUtils(false)
.setVideoAllCallBack(new GSYSampleCallBack() {
@Override
public void onPrepared(String url, Object... objects) {
super.onPrepared(url, objects);
//开始播放了才能旋转和全屏
//orientationUtils.setEnable(detailPlayer.isRotateWithSystem());
isPlay = true;
}
@Override
public void onQuitFullscreen(String url, Object... objects) {
super.onQuitFullscreen(url, objects);
// ------- !!!如果不需要旋转屏幕,可以不调用!!!-------
// 不需要屏幕旋转,还需要设置 setNeedOrientationUtils(false)
// 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);
detailPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//直接横屏
// ------- !!!如果不需要旋转屏幕,可以不调用!!!-------
// 不需要屏幕旋转,还需要设置 setNeedOrientationUtils(false)
// orientationUtils.resolveByClick();
//第一个true是否需要隐藏actionbar,第二个true是否需要隐藏statusbar
detailPlayer.startWindowFullscreen(SimpleDetailActivityMode2.this, true, true);
}
});
}
@Override
public void onBackPressed() {
// ------- !!!如果不需要旋转屏幕,可以不调用!!!-------
// 不需要屏幕旋转,还需要设置 setNeedOrientationUtils(false)
// if (orientationUtils != null) {
// orientationUtils.backToProtVideo();
// }
if (GSYVideoManager.backFromWindowFull(this)) {
return;
}
super.onBackPressed();
}
@Override
protected void onPause() {
detailPlayer.getCurrentPlayer().onVideoPause();
super.onPause();
isPause = true;
}
@Override
protected void onResume() {
detailPlayer.getCurrentPlayer().onVideoResume(false);
super.onResume();
isPause = false;
}
@Override
protected void onDestroy() {
super.onDestroy();
if (isPlay) {
detailPlayer.getCurrentPlayer().release();
}
// if (orientationUtils != null)
// orientationUtils.releaseListener();
}
/**
* orientationUtils 和 detailPlayer.onConfigurationChanged 方法是用于触发屏幕旋转的
*/
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//如果旋转了就全屏
// if (isPlay && !isPause) {
// detailPlayer.onConfigurationChanged(this, newConfig, orientationUtils, true, true);
// }
}
}