个别操作需要有相应的声音提醒,

来源:互联网 发布:怎么注册淘宝 编辑:程序博客网 时间:2024/05/16 07:28

公司项目是与足球类相关的app,当有进球时,红牌时等等,项目中h5界面 需要发出相应的声音 ,所以需要js 调用我们发出声音,

下面分享一些  播放本地声音的小组件 


/** * 播放新消息的声音(单个) * * @param key 文件对应的键 */public static void playSound(int key) {    mPool.play(soundArr.get(key), 1, 1, 0, 0, 1);}private static SoundPool mPool = new SoundPool(5, AudioManager.STREAM_SYSTEM, 5);private static SparseIntArray soundArr = new SparseIntArray();/** * 设置声音池 * * @param resId *            文件id *//** * 设置声音池 * * @param key   文件对应的键 * @param resId 文件id */public static void setSoundPool(int key, int resId) {    soundArr.put(key, mPool.load(Global.mContext, resId, 1));}
播放时,只需要调用 playSound()方法即可,  传入本地的声音文件对应的资源id,就阔以播放了,
playSound
playSound
playSound
playSound

0 0