AudioTrack,的Soundpool或MediaPlayer的哪一个我应该使用? [英] AudioTrack, SoundPool or MediaPlayer Which Should I use?

查看:116
本文介绍了AudioTrack,的Soundpool或MediaPlayer的哪一个我应该使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要发挥多个音频文件,具有不同的时间,像5到30秒。我想单独设置音量左/右声道,并应用效果,如混响或失真。所以,我应该使用哪种API?

I need to play multiple audio files, with different duration, like 5 to 30 seconds. And i want to set volume independently for right/left channel and also to apply effects, like Reverb or Distortion. So, Which API should i use?

另外,我找不到AudioTrack API太多的文档。你知道我在哪里可以找到例子吗? THX。

Also, i can't find too much doc on AudioTrack API. Do you know where can i find examples? Thx.

推荐答案

声音池实际上是音频混合器。它可以播放短片只,无论他们是否连接codeD作为OGG或MP3或他们uncom pressed。声音池总是将它们存储在内存中uncom pressed,你必须知道,限制为1 MB。如果您的素材是过于庞大,内存,声卡池将落地无声,你会发现以下错误: AudioFlinger无法创建跟踪状态:-12 媒体播放器播放流去code是实时的。因此,它可以播放更长时间的剪辑,但需要处理器电源吧。

Sound pool is actually audio mixer. It can play short clips only regardless of whether they are encoded as ogg or mp3 or they are uncompressed. Sound pool always store them in memory uncompressed, and you must know that limit is 1 MB. If your clip is too big in memory, sound pool will fall silent, and you'll find following error: "AudioFlinger could not create track. status: -12" Media player plays stream and decode it in real time. So it can play much longer clips but needs processor power for it.

所以,媒体播放器是背景音乐更好,而声音池是更好的堡垒短音频效果(点击,爆炸,声音循环)。此外,完善的池可以同时播放多个剪辑,并具有音量和速度控制。此外,它可以播放循环。

So Media player is better for background music, while sound pool is better fort short audio effects (clicks, explosions, sound loops). In addition, sound pool can play more clips simultaneously, and has volume and speed control. Also it can play loops.

一注:不能从声音库播放音乐,如果剪辑没有完全加载和去codeD。所以,你必须使用OnLoadCompleteListener(安卓10或以上)进行检查。如果您尝试播放声音是德codeD之前,声池将静音。

One note: you can't play music from sound pool if clip isn't fully loaded and decoded. So you must use OnLoadCompleteListener (Android 10 or above) to check it. If you try to play sound before it is decoded, sound pool will be mute.

媒体播放器并没有从这些问题的困扰。

Media player doesn't suffer from these problems.

这篇关于AudioTrack,的Soundpool或MediaPlayer的哪一个我应该使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆