PlayActivity.java
4.91 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
/*
* Copyright (c) Wondertek Technologies Co., Ltd. 2019-2022. All rights reserved.
*/
package com.wd.player;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.aliyun.player.source.UrlSource;
import com.aliyun.svideo.wd.player.R;
import com.wd.player.playerutil.ScreenUtils;
import com.wd.player.widget.VideoAndLivePlayerView;
/**
* 描述:播放器组件待完善
*
* @author : lvjinhui
* @since: 2022/7/1
*/
public class PlayActivity extends AppCompatActivity {
/**
* 播放器视图
*/
private VideoAndLivePlayerView aliyunRenderView;
private boolean isInit = false;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play);
aliyunRenderView = findViewById(R.id.playerView);
}
@Override
protected void onStart() {
super.onStart();
}
private void initPlayer() {
UrlSource urlSource = new UrlSource();
// urlSource.setUri(PlayParameter.PLAY_PARAM_URL);
initDataSource(urlSource);
}
private void initDataSource(UrlSource urlSource) {
if (urlSource == null) {
return;
}
aliyunRenderView.setLocalSource(urlSource);
}
/**
* 播放器
*
* @param keyCode
* @param event
* @return
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (aliyunRenderView != null) {
boolean handler = aliyunRenderView.onKeyDown(keyCode, event);
if (!handler) {
return false;
}
}
return super.onKeyDown(keyCode, event);
}
@Override
protected void onResume() {
super.onResume();
if (!isInit){
initPlayer();
}
isInit = true;
updatePlayerViewMode();
if (aliyunRenderView != null) {
aliyunRenderView.setAutoPlay(true);
aliyunRenderView.onResume();
}
}
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onStop() {
super.onStop();
if (aliyunRenderView != null) {
aliyunRenderView.setAutoPlay(false);
aliyunRenderView.onStop();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (aliyunRenderView != null) {
aliyunRenderView.onDestroy();
aliyunRenderView = null;
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
updatePlayerViewMode();
}
private void updatePlayerViewMode() {
if (aliyunRenderView != null) {
int orientation = getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
aliyunRenderView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
// 设置view的布局,宽高之类
RelativeLayout.LayoutParams aliVcVideoViewLayoutParams =
(RelativeLayout.LayoutParams) aliyunRenderView.getLayoutParams();
aliVcVideoViewLayoutParams.height = (int) (ScreenUtils.getWidth(this) * 9.0f / 16);
aliVcVideoViewLayoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
// 转到横屏了。
// 隐藏状态栏
// if (!ToolsUtil.isStrangePhone()) {
// this.getWindow()
// .setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
// WindowManager.LayoutParams.FLAG_FULLSCREEN);
// aliyunRenderView.setSystemUiVisibility(
// View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
// | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
// | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
// }
// 设置view的布局,宽高
RelativeLayout.LayoutParams aliVcVideoViewLayoutParams =
(RelativeLayout.LayoutParams) aliyunRenderView.getLayoutParams();
aliVcVideoViewLayoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
aliVcVideoViewLayoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
}
}
}
}