android中使用soundpool播放mp3和ogg格式的区别

本文对比了MP3和OGG两种格式在SoundPool中播放的效率与资源消耗。测试显示,尽管OGG文件更小,但MP3在播放速度上表现更优,平均时间为56.55ms,而OGG为71.05ms。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

因为在开发中有需要频繁播放音效的需要,所以使用了soundpool,在网上查看相关文档对于soundpool可以播放的音频文件及格式没有明确的规定,现在就当下流行的音效mp3和ogg进行对比;
1、大小:相同音效的文件不到1s,mp3会比ogg大很多,我这边测试用的mp3文件大小为35k,通过迅捷视频转换器转换后的ogg只有9k;
2、时间:ogg文件分别播放20次用的时间如下
11-19 11:30:18.867 7424-7424/com D/sound time: 54
11-19 11:30:24.945 7424-7424/com D/sound time: 82
11-19 11:30:27.543 7424-7424/com D/sound time: 102
11-19 11:30:28.674 7424-7424/com D/sound time: 74
11-19 11:30:29.827 7424-7424/com D/sound time: 65
11-19 11:30:31.053 7424-7424/com D/sound time: 74
11-19 11:30:32.291 7424-7424/com D/sound time: 60
11-19 11:30:33.560 7424-7424/com D/sound time: 76
11-19 11:30:34.798 7424-7424/com D/sound time: 62
11-19 11:30:36.097 7424-7424/com D/sound time: 77
11-19 11:30:37.356 7424-7424/com D/sound time: 61
11-19 11:30:38.615 7424-7424/com D/sound time: 57
11-19 11:30:39.917 7424-7424/com D/sound time: 74
11-19 11:30:41.165 7424-7424/com D/sound time: 80
11-19 11:30:42.467 7424-7424/com D/sound time: 96
11-19 11:30:43.693 7424-7424/com D/sound time: 71
11-19 11:30:45.026 7424-7424/com D/sound time: 60
11-19 11:30:46.306 7424-7424/com D/sound time: 65
11-19 11:30:47.607 7424-7424/com D/sound time: 67
11-19 11:30:48.887 7424-7424/com D/sound time: 64
mp3文件分别播放20次用的时间如下:
11-19 13:36:54.978 29752-29752/com D/sound time: 44
11-19 13:36:56.573 29752-29752/com D/sound time: 62
11-19 13:36:57.821 29752-29752/com D/sound time: 55
11-19 13:36:59.080 29752-29752/com D/sound time: 58
11-19 13:37:00.328 29752-29752/com D/sound time: 52
11-19 13:37:01.608 29752-29752/com D/sound time: 54
11-19 13:37:02.899 29752-29752/com D/sound time: 67
11-19 13:37:04.158 29752-29752/com D/sound time: 49
11-19 13:37:05.289 29752-29752/com D/sound time: 59
11-19 13:37:06.398 29752-29752/com D/sound time: 47
11-19 13:37:07.603 29752-29752/com D/sound time: 74
11-19 13:37:08.713 29752-29752/com D/sound time: 50
11-19 13:37:09.916 29752-29752/com D/sound time: 65
11-19 13:37:11.046 29752-29752/com D/sound time: 53
11-19 13:37:12.167 29752-29752/com D/sound time: 53
11-19 13:37:13.341 29752-29752/com D/sound time: 73
11-19 13:37:14.461 29752-29752/com D/sound time: 49
11-19 13:37:15.624 29752-29752/com D/sound time: 56
11-19 13:37:16.766 29752-29752/com D/sound time: 65
11-19 13:37:18.035 29752-29752/com D/sound time: 46
ogg的平均时间是71.05ms
mp3的平均时间是56.55ms
两个文件的播放时间相比mp3更快一些。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值