lmw
2023-06-16 03972ad1d3ce6ffe0be0395c0a4d5dcb4474031f
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
package com.luck.picture.lib.tools;
 
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Handler;
 
import com.luck.picture.lib.R;
 
/**
 * @author:luck
 * @data:2017/5/25 19:12
 * @描述: voice utils
 */
public class VoiceUtils {
    private static SoundPool soundPool;
    private static int soundID;//创建某个声音对应的音频ID
 
    /**
     * start SoundPool
     */
    public static void playVoice(Context mContext, final boolean enableVoice) {
 
        if (soundPool == null) {
            soundPool = new SoundPool(1, AudioManager.STREAM_ALARM, 0);
            soundID = soundPool.load(mContext, R.raw.picture_music, 1);
        }
        new Handler().postDelayed(() -> play(enableVoice, soundPool), 20);
    }
 
    public static void play(boolean enableVoice, SoundPool soundPool) {
        if (enableVoice) {
            soundPool.play(
                    soundID,
                    0.1f,
                    0.5f,
                    0,
                    1,
                    1
            );
        }
    }
}