国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android學習之工具類二:播放聲音工具類

2019-11-09 18:03:53
字體:
來源:轉載
供稿:網友
?import android.content.Context;import android.media.AudioManager;import android.media.SoundPool;/** * 播放聲音工具類 * * @author linzhiyong * @time 2017-01-16 10:11:16 * @email wflinzhiyong@163.com * @desc */public class SoundPlayer {    PRivate Context context;    private SoundPool soundPool;    private int soundID;    public SoundPlayer(Context context) {        this.context = context;        this.soundPool= new SoundPool(10, AudioManager.STREAM_SYSTEM, 5);    }    /**     * 加載聲音資源     *     * @param resId     * @return soundID     */    public int loadRes(int resId) {        return this.soundPool.load(this.context, resId, 1);    }    /**     * 播放聲音     *     * @param soundID     * @param priority     * @param isLoop     */    public void play(int soundID, int priority, boolean isLoop) {        this.soundPool.play(soundID, 1, 1, priority, isLoop ? -1 : 0, 1);    }    /**     * 停止     *     * @param soundID     */    public void stop(int soundID) {        this.soundPool.stop(soundID);        this.soundPool.release();    }    /**     * 播放聲音     *     * @param resId     * @param isLoop     */    public void play(int resId, final boolean isLoop) {        this.soundID = loadRes(resId);        this.soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {            @Override            public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {                play(soundID, 0, isLoop);            }        });    }    /**     * 停止     */    public void stop() {        stop(this.soundID);    }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 涪陵区| 集贤县| 阳东县| 磐石市| 麦盖提县| 深水埗区| 吉首市| 平顺县| 揭东县| 马尔康县| 潞城市| 同德县| 信宜市| 迭部县| 德庆县| 固阳县| 临桂县| 莱西市| 三原县| 祁门县| 安新县| 舒兰市| 宝坻区| 宁海县| 塔城市| 孟津县| 安多县| 云林县| 思南县| 长沙县| 石门县| 惠州市| 盘锦市| 神池县| 湘阴县| 丽江市| 太康县| 乌苏市| 大方县| 张北县| 丹巴县|