阅读:2497回复:2
Mediaplayer播放提示音问题
客户的App使用MediaPlayer播放assets目录的ogg后缀的提示音没有声音,在rk3288-7.1使用没有问题,在9.0测试时候没有声音,我做了demo试了一下确实没有声音,assets目录放一些长一点的提示音和MP3都是正常的,但是放很短比如1秒左右的提示音就是没有声音,但是放在sdcard目录播放又有声音,看打印也看不出什么问题来,其实MediaPlayer占用资源大延迟高,并不太适合播放简短的提示音,使用SoundPool播放没有问题。
SoundPool soundPool; |
|
|
沙发#
发布于:2022-09-21 17:59
以前封装的接口: public class SoundPoolUtil { private static SoundPoolUtil soundPoolUtil; private SoundPool soundPool; //单例模式 public static SoundPoolUtil getInstance(Context context) { if (soundPoolUtil == null) soundPoolUtil = new SoundPoolUtil(context); return soundPoolUtil; } private SoundPoolUtil(Context context) { soundPool = new SoundPool(3, AudioManager.STREAM_SYSTEM, 0); //加载音频文件 soundPool.load(context, R.raw.tishi, 1); } public void play5Times() { soundPool.play(1, 1, 1, 0, 4, 0.7f); } public void play() { soundPool.play(1, 1, 1, 0, 0, 1); } } |
|
板凳#
发布于:2022-12-30 17:32
frameworks/av/media$ 播放简短提示音的问题可以这样修改 |
|
|