forked from TheWidlarzGroup/react-native-video
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFullScreenVideoActivity.java
173 lines (142 loc) · 4.45 KB
/
FullScreenVideoActivity.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
162
163
164
165
166
167
168
169
170
171
172
173
package com.brentvatne.react;
import android.app.Activity;
import android.media.MediaPlayer;
import android.widget.VideoView;
import android.view.MotionEvent;
import android.os.Bundle;
import android.view.View;
import android.widget.MediaController;
import com.brentvatne.react.ReactMediaController;
import android.content.Intent;
import android.widget.ProgressBar;
import android.view.SurfaceView;
import android.view.SurfaceHolder;
import com.brentvatne.react.ReactVideoView;
public class FullScreenVideoActivity extends Activity implements MediaPlayer.OnPreparedListener,
MediaPlayer.OnCompletionListener, MediaPlayer.OnInfoListener, MediaController.MediaPlayerControl,
MediaPlayer.OnBufferingUpdateListener {
private SurfaceView mSurfaceView;
private ReactMediaController mMediaController;
final private MediaPlayer mMediaPlayer = ReactVideoView.getMediaPlayer(false);
private ProgressBar mProgressBar;
private int mBufferProgress = 0;
@Override
public void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.videoplayer);
mProgressBar = (ProgressBar) findViewById(R.id.progressbar);
mSurfaceView = (SurfaceView)findViewById(R.id.surfaceview);
mMediaPlayer.setOnInfoListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnBufferingUpdateListener(this);
mSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
mMediaPlayer.setDisplay(surfaceHolder);
}
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int m, int n, int p) {}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {}
});
initializeMediaControllerIfNeeded();
mMediaController.setMediaPlayer(this);
mMediaController.setAnchorView(mSurfaceView);
mMediaController.setDoneOnClickListenter(new View.OnClickListener() {
public void onClick(View v) {
done();
}
});
}
@Override
public void onBackPressed() {
done();
}
@Override
public void onPrepared(MediaPlayer mp) {
mProgressBar.setVisibility(View.GONE);
}
@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
mBufferProgress = percent;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
initializeMediaControllerIfNeeded();
mMediaController.show();
return super.onTouchEvent(event);
}
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
if (what == MediaPlayer.MEDIA_INFO_BUFFERING_START) {
mProgressBar.setVisibility(View.VISIBLE);
}
if (what == MediaPlayer.MEDIA_INFO_BUFFERING_END) {
mProgressBar.setVisibility(View.GONE);
}
return false;
}
@Override
public int getCurrentPosition() {
return mMediaPlayer.getCurrentPosition();
}
@Override
public int getDuration() {
return mMediaPlayer.getDuration();
}
@Override
public void pause() {
mMediaPlayer.pause();
}
@Override
public void start() {
mMediaPlayer.start();
}
@Override
public boolean isPlaying() {
return mMediaPlayer.isPlaying();
}
@Override
public void seekTo(int msec) {
mMediaPlayer.seekTo(msec);
}
public void stopPlaying() {
mMediaPlayer.stop();
mMediaPlayer.release();
done();
}
@Override
public int getBufferPercentage() {
return mBufferProgress;
}
@Override
public boolean canPause() {
return true;
}
@Override
public boolean canSeekBackward() {
return false;
}
@Override
public boolean canSeekForward() {
return false;
}
@Override
public int getAudioSessionId() {
return 0;
}
@Override
public void onCompletion(MediaPlayer mp) {
}
private void done() {
mMediaPlayer.setSurface(ReactVideoView.surface);
Intent returnIntent = new Intent();
setResult(Activity.RESULT_OK,returnIntent);
finish();
}
private void initializeMediaControllerIfNeeded() {
if (mMediaController == null) {
mMediaController = new ReactMediaController(this, false);
}
}
}