This repository was archived by the owner on Aug 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 413
Expand file tree
/
Copy pathMusic.java
More file actions
66 lines (54 loc) · 1.36 KB
/
Music.java
File metadata and controls
66 lines (54 loc) · 1.36 KB
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
package com.snatik.matches.common;
import android.content.SharedPreferences;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import com.snatik.matches.R;
public class Music {
public static boolean OFF = false;
private static MediaPlayer mediaPlayer;
public static void playCorrent() {
if (!OFF) {
MediaPlayer mp = MediaPlayer.create(Shared.context, R.raw.correct_answer);
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.reset();
mp.release();
mp = null;
}
});
mp.start();
}
}
public static void playBackgroundMusic() {
mediaPlayer = MediaPlayer.create(Shared.context, R.raw.background_music);
if(isMusicOn()) {
mediaPlayer.start();
mediaPlayer.setLooping(true);
}
OFF = false;
}
public static void showStar() {
if (!OFF) {
MediaPlayer mp = MediaPlayer.create(Shared.context, R.raw.star);
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.reset();
mp.release();
mp = null;
}
});
mp.start();
}
}
public static void stopBackgroundMusic(){
if(mediaPlayer.isPlaying()) {
mediaPlayer.stop();
OFF = true;
}
}
public static boolean isMusicOn(){
return !OFF;
}
}