forked from hitherejoe/Vineyard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoopingVideoView.java
54 lines (43 loc) · 1.54 KB
/
LoopingVideoView.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
package com.hitherejoe.vineyard.ui.widget;
import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;
import android.util.AttributeSet;
import android.widget.VideoView;
public class LoopingVideoView extends VideoView {
private MediaPlayer mMediaPlayer;
public LoopingVideoView(Context context) {
super(context);
}
public LoopingVideoView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public LoopingVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public LoopingVideoView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public void setupMediaPlayer(String url, final OnVideoReadyListener onVideoReadyListener) {
setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mMediaPlayer = mp;
mMediaPlayer.setLooping(true);
mMediaPlayer.setVolume(0, 0);
mMediaPlayer.start();
onVideoReadyListener.onVideoReady();
}
});
setVideoURI(Uri.parse(url));
}
public void stopMediaPlayer() {
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
mMediaPlayer.stop();
mMediaPlayer = null;
}
}
public interface OnVideoReadyListener {
void onVideoReady();
}
}