Repository navigation
Expand file tree
/
Copy pathPlayPickActivity.java
More file actions
186 lines (152 loc) · 6.18 KB
/
Copy pathPlayPickActivity.java
File metadata and controls
186 lines (152 loc) · 6.18 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package com.example.gsyvideoplayer;
import android.annotation.TargetApi;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import androidx.core.view.ViewCompat;
import androidx.appcompat.app.AppCompatActivity;
import android.transition.Transition;
import android.view.View;
import android.widget.ImageView;
import androidx.activity.OnBackPressedCallback;
import com.example.gsyvideoplayer.databinding.ActivityPlayPickBinding;
import com.example.gsyvideoplayer.listener.OnTransitionListener;
import com.example.gsyvideoplayer.model.SwitchVideoModel;
import com.example.gsyvideoplayer.utils.DemoVideoUrls;
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.utils.OrientationUtils;
import java.util.ArrayList;
import java.util.List;
/**
* 单独的视频播放页面
* Created by shuyu on 2016/11/11.
*/
public class PlayPickActivity extends AppCompatActivity {
public final static String IMG_TRANSITION = "IMG_TRANSITION";
public final static String TRANSITION = "TRANSITION";
OrientationUtils orientationUtils;
private boolean isTransition;
private Transition transition;
private ActivityPlayPickBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityPlayPickBinding.inflate(getLayoutInflater());
View rootView = binding.getRoot();
setContentView(rootView);
isTransition = getIntent().getBooleanExtra(TRANSITION, false);
init();
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
//先返回正常状态
if (orientationUtils.getScreenType() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
binding.videoPlayer.getFullscreenButton().performClick();
return;
}
//释放所有
binding.videoPlayer.setVideoAllCallBack(null);
GSYVideoManager.releaseAllVideos();
if (isTransition && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
finishAfterTransition();
} else {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
finish();
overridePendingTransition(androidx.appcompat.R.anim.abc_fade_in, androidx.appcompat.R.anim.abc_fade_out);
}
}, 500);
}
}
});
}
private void init() {
//借用了jjdxm_ijkplayer的URL
String source1 = DemoVideoUrls.HLS_BIPBOP_GEAR1;
String name = "普通";
SwitchVideoModel switchVideoModel = new SwitchVideoModel(name, source1);
String source2 = DemoVideoUrls.HLS_BIPBOP_GEAR3;
String name2 = "清晰";
SwitchVideoModel switchVideoModel2 = new SwitchVideoModel(name2, source2);
List<SwitchVideoModel> list = new ArrayList<>();
list.add(switchVideoModel);
list.add(switchVideoModel2);
binding.videoPlayer.setUp(list, false, "测试视频");
//增加封面
ImageView imageView = new ImageView(this);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageResource(R.mipmap.xxx1);
binding.videoPlayer.setThumbImageView(imageView);
//增加title
binding.videoPlayer.getTitleTextView().setVisibility(View.VISIBLE);
//设置返回键
binding.videoPlayer.getBackButton().setVisibility(View.VISIBLE);
//设置旋转
orientationUtils = new OrientationUtils(this, binding.videoPlayer);
//设置全屏按键功能,这是使用的是选择屏幕,而不是全屏
binding.videoPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// ------- !!!如果不需要旋转屏幕,可以不调用!!!-------
// 不需要屏幕旋转,还需要设置 setNeedOrientationUtils(false)
orientationUtils.resolveByClick();
}
});
//是否可以滑动调整
binding.videoPlayer.setIsTouchWiget(true);
//设置返回按键功能
binding.videoPlayer.getBackButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getOnBackPressedDispatcher().onBackPressed();
}
});
//过渡动画
initTransition();
}
@Override
protected void onPause() {
super.onPause();
binding.videoPlayer.onVideoPause();
}
@Override
protected void onResume() {
super.onResume();
binding.videoPlayer.onVideoResume();
}
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
protected void onDestroy() {
super.onDestroy();
if (orientationUtils != null)
orientationUtils.releaseListener();
}
private void initTransition() {
if (isTransition && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
postponeEnterTransition();
ViewCompat.setTransitionName(binding.videoPlayer, IMG_TRANSITION);
addTransitionListener();
startPostponedEnterTransition();
} else {
binding.videoPlayer.startPlayLogic();
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private boolean addTransitionListener() {
transition = getWindow().getSharedElementEnterTransition();
if (transition != null) {
transition.addListener(new OnTransitionListener(){
@Override
public void onTransitionEnd(Transition transition) {
super.onTransitionEnd(transition);
binding.videoPlayer.startPlayLogic();
transition.removeListener(this);
}
});
return true;
}
return false;
}
}