-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmedaiplayer.java
67 lines (48 loc) · 1.75 KB
/
medaiplayer.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
public class medaiplayer {
}
////////////// Media Player
Button btnPause, btnPlay, btnStop;
@Override
btnPause = findViewById(R.id.btnPause);
btnPlay = findViewById(R.id.btnPlay);
btnStop = findViewById(R.id.btnStop);
MediaPlayer mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
String aPath = "android.resource://"+getPackageName()+"/raw/song2";
String onlineAudioPath = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3";
Uri audioURI = Uri.parse(aPath);
try{
mp.setDataSource(this,audioURI);
mp.prepare();
}
catch (Exception e){
}
btnPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mp.start();
}
});
btnPause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mp.pause();
}
});
btnStop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mp.pause();
mp.seekTo(0);
}
});
//mp.seekTo(0); // play the audio from from where ever we want to satrt
// mp.getDuration() to skip the song with specific seconds
// mp.getCurrentPosition();
// setOnCompletionListener is used when the song is finished and we want to play next song.
/* mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
}
});*/
}}