VideoActivity.java
1.7 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
package com.cnlive.im.ui;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.VideoView;
import com.cnlive.im.R;
/**
* Created by gujun on 2017/12/12.
*/
public class VideoActivity extends Activity {
private String videoPath;
private VideoView videoView;
private boolean isStart = false;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play);
init(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
init(intent);
}
private void init(Intent intent) {
videoPath = intent.getStringExtra("videoPath");
videoView = (VideoView) findViewById(R.id.video);
videoView.setVideoPath(videoPath);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
isStart = true;
videoView.start();
}
});
}
@Override
protected void onResume() {
super.onResume();
if (videoView != null && isStart) {
videoView.start();
}
}
@Override
protected void onPause() {
super.onPause();
if (videoView != null && isStart) {
videoView.pause();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (videoView != null) {
videoView.stopPlayback();
videoView = null;
}
}
}