-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathSamplePlayerActivity.java
63 lines (53 loc) · 2.19 KB
/
SamplePlayerActivity.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
package com.videffects.sample.view;
import android.app.Activity;
import android.content.res.AssetFileDescriptor;
import android.content.res.Resources;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import com.sherazkhilji.sample.R;
import com.sherazkhilji.videffects.DuotoneEffect;
import com.sherazkhilji.videffects.view.VideoSurfaceView;
public class SamplePlayerActivity extends Activity {
private static final String TAG = "SamplePlayerActivity";
protected Resources mResources;
private VideoSurfaceView mVideoView = null;
private MediaPlayer mMediaPlayer = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mResources = getResources();
mMediaPlayer = new MediaPlayer();
try {
// Load video file from SD Card
// File dir = Environment
// .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
// File file = new File(dir,
// "sample.mp4");
// mMediaPlayer.setDataSource(file.getAbsolutePath());
// -----------------------------------------------------------------------
// Load video file from Assets directory
AssetFileDescriptor afd = getAssets().openFd("sample.mp4");
mMediaPlayer.setDataSource(afd.getFileDescriptor(),
afd.getStartOffset(), afd.getLength());
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
// Initialize VideoSurfaceView using code
// mVideoView = new VideoSurfaceView(this);
// setContentView(mVideoView);
// or
setContentView(R.layout.activity_sampleplayer);
mVideoView = (VideoSurfaceView) findViewById(R.id.mVideoSurfaceView);
mVideoView.init(mMediaPlayer,
new DuotoneEffect(Color.parseColor("#3498DB"), Color.YELLOW));
// If you want to change effect then just call mVideoView.init() again
// and then call mVideoView.onResume()
}
@Override
protected void onResume() {
super.onResume();
mVideoView.onResume();
}
}