package qianfeng.day04_camera;
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Build;
/**
* Created by keven on 16/6/30.
*/
public class SoundPoolUtils {
/**
* 单独开辟线程 播放声音
*/
SoundPool mPool;
private final int music;
public SoundPoolUtils(Context context){
if(Build.VERSION.SDK_INT>=21){
//setMaxStreams 同时最大播放数量
mPool = new SoundPool.Builder().setMaxStreams(1).build();
}else{
//int maxStreams,最大播放数 int streamType,流类型 int srcQuality采样率,没有用 默认0
mPool = new SoundPool(1, AudioManager.STREAM_MUSIC,0);
}
//返回的是 pool资源ID
music = mPool.load(context, R.raw.kaka, 1);
}
public void play(){
/**
* @param soundID 声音资源ID
* @param leftVolume 左音量 (范围 = 0.0 to 1.0)
* @param rightVolume 右音量 (范围 = 0.0 to 1.0)
* @param priority 流的优先级 (0 = lowest priority)
* @param loop 是否循环播放 0不循环 -1 无限循环 3 循环3+1次
* @param rate 播放速率 默认1.0 范围0.5 到 2.0 之间 (1.0 = normal playback, range 0.5 to 2.0)
*/
mPool.play(music,1,1,1,0,1);
}
}