-
Notifications
You must be signed in to change notification settings - Fork 9
/
Simple_audio_media_player.pde
68 lines (60 loc) · 1.27 KB
/
Simple_audio_media_player.pde
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
import android.media.MediaPlayer;
import android.content.res.Resources;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.content.Context;
import android.app.Activity;
MediaPlayer player = new MediaPlayer();
AssetFileDescriptor fd;
Context context;
Activity activity;
String sound_file_name = "Over_the_horizon.mp3";
void setup() {
fullScreen();
background(0, 0, 200);
orientation(PORTRAIT);
textSize(60);
textAlign(CENTER, CENTER);
activity = this.getActivity();
context = activity.getApplicationContext();
try {
fd = context.getAssets().openFd(sound_file_name);
player.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
}
catch (IOException e) {
e.printStackTrace();
}
text("Press to start", width/2, height/2);
}
void draw() {
}
void mousePressed() {
try {
player.prepare();
player.start();
}
catch (Exception e) {
e.printStackTrace();
}
}
void onPause() {
super.onPause();
if (player!=null) {
player.release();
player= null;
}
}
void onStop() {
super.onStop();
if (player!=null) {
player.release();
player= null;
}
}
void onDestroy() {
super.onDestroy();
if (player!=null) {
player.release();
player= null;
}
}