VideoViewActivity.java
3.14 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
package com.cnlive.demo.video;
import android.app.Activity;
import android.os.Bundle;
import com.cnlive.demo.video.model.ProgramVod;
import com.cnlive.libs.video.video.VideoView;
import com.cnlive.libs.video.video.base.IMediaPlayer;
import static com.cnlive.libs.util.auth.AuthUtil.AUTH_ERROR;
import static com.cnlive.libs.util.auth.AuthUtil.AUTH_SUCCESS;
public class VideoViewActivity extends Activity {
protected VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_videoview);
initPlay();
}
@Override
protected void onPause() {
super.onPause();
videoView.pause();
}
@Override
protected void onResume() {
super.onResume();
videoView.start();
}
@Override
protected void onDestroy() {
super.onDestroy();
videoView.release();
}
private void initPlay() {
videoView = (VideoView) findViewById(R.id.videoview);
//认证APP播放权限(使用视讯中国资源)
videoView.auth();
videoView.setOnBufferingUpdateListener(new IMediaPlayer.OnBufferingUpdateListener() {
@Override
public void onBufferingUpdate(IMediaPlayer mediaplayer, int percent) {
}
});
videoView.setOnPlayStateListener(new IMediaPlayer.OnPlayStateListener() {
@Override
public void onPlayState(boolean isPlay) {
}
});
videoView.setOnInfoListener(new IMediaPlayer.OnInfoListener() {
@Override
public boolean onInfo(IMediaPlayer mediaplayer, int what, int extra) {
switch (what) {
case AUTH_SUCCESS:
// auth = true;
startPlay();
break;
}
return false;
}
});
videoView.setOnErrorListener(new IMediaPlayer.OnErrorListener() {
@Override
public boolean onError(IMediaPlayer mediaplayer, int what, int extra) {
switch (what) {
case AUTH_ERROR:
break;
}
return false;
}
});
videoView.setOnPreparedListener(new IMediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(IMediaPlayer mediaplayer) {
mediaplayer.start();
}
});
videoView.setOnCompletionListener(new IMediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(IMediaPlayer mediaplayer) {
}
});
startPlay();
}
private void startPlay() {
//视讯云 直播
// videoView.setDataSource(new ProgramLive(),false);
//视讯云 点播
videoView.setDataSourceByAuth(new ProgramVod(), false);
//本地视频
// try {
// videoView.setDataSource("rtmp://live.hkstv.hk.lxdns.com/live/hks");
// } catch (IOException e) {
// e.printStackTrace();
// }
}
}