a
554325746@qq.com
2019-10-24 c61e776980f038bb0e195f7753a3d7e127d6028f
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
package com.basic.security.utils;
 
import android.media.MediaPlayer;
 
import com.basic.security.R;
import com.basic.security.base.BaseApplication;
 
public class AudioPlayer {
 
    public static MediaPlayer play(MediaPlayer mp) {
        try {
            if (mp == null) {
                mp = MediaPlayer.create(BaseApplication.getApplication().activity, R.raw.dingdong);
                mp.setLooping(false);
                mp.start();
            } else {
                if (!mp.isPlaying()) {
                    mp.stop();
                    mp.release();
                    mp = MediaPlayer.create(BaseApplication.getApplication().activity, R.raw.dingdong);
                    mp.setLooping(false);
                    mp.start();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
 
        return mp;
    }
 
    public static void stopInNewThread(final MediaPlayer mp) {
 
        BaseApplication.getApplication().executorService.execute(() -> {
            AudioPlayer.stop(mp);
        });
    }
 
    public static void stop(MediaPlayer mp) {
        try {
            if (mp != null && mp.isPlaying()) {
                mp.stop();
                mp.release();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
 
    }
 
}