问题描述
我有一个问题的Soundpool,因为它拒绝与我的.ogg文件的工作。我收到此错误:
I am having a problem With SoundPool as it refuses to work with my .ogg files. I am getting this error:
AudioFlinger无法创建跟踪,状态:-12 的
错误创建AudioTrack 的
AudioFlinger could not create track, status: -12
Error creating AudioTrack
我发现有关这个和(可能的)一个线程answer是:
I've found a thread concerning this and the (possible) answer is:
- 确保您使用的.ogg媒体文件与恒定比特率!
这是如此吗? (有人请确认或取消)
如果是的话 - 要使用的应用程序(Audacity的不支持.OGG自定义导出设置)
如果没有 - ?还有什么可能是错误的。
Is this the case? (someone please confirm or cancel)
If yes - which application to use (Audacity doesn't support .ogg custom export settings).
If not - what else could be wrong?
作为一个方面说明 - 以前我用过的MediaPlayer,但现在我想播放声音并行数
As a side note - before I used MediaPlayer but now I want to play a few sounds parallel.
推荐答案
主要编辑:找到一种方法来修复你的一天!滚动向下跌破!!
我是在同一条船上你。读书之前,我必须让你知道,我无法提供,可以解决这一问题的答案。
I'm in the same boat with you. Before reading, I must let you know that I failed to provide an answer that can fix this problem.
我看过很多很多堆栈溢出有关的Soundpool的话题,但我还没有看到很多的Soundpool问题,这方面与Java code从Android的书:
I have seen many, many Stack Overflow topics regarding SoundPool, but I haven't seen a lot of SoundPool problems with this in regard with Java code from an Android book:
AudioTrack:AudioFlinger无法创建跟踪,状态-12
的Soundpool:错误创建AudioTrack
这里的code,从这里开始提供安卓4.0游戏开发源$ C $ C(见下文)剪断。你得到的explosion.ogg文件存在(在树干上,找到第4章的/资产的文件夹 - Android的基础)。你必须在你的右边来获取文件点击查看原始文件。
Here's the code snipped from Beginning Android 4 Game Development source code provided here (see below). You get the explosion.ogg file there (in the trunk, find the /asset folder of Chapter 4 - Android Basics). You have to click on "View raw file" on your right to obtain the file.
我所做的只是我直接复制源$ C $ C到Eclipse,并添加从树干中提供的explosion.ogg文件,到我的项目。我执行的Android模拟器,试图播放文件,我可以告诉你,我仍然得到上面引述同一logcat中的错误。
All I did was I copied the source code directly into Eclipse, and added the explosion.ogg file provided from the trunk, into my project. I executed Android emulator, tried playing the file, and I can tell you I still get the same Logcat errors quoted above.
一个人提供的视频在Youtube上指出的Soundpool正常工作。下面的视频链接给出。我做了视频指示我code,我抓住我从上面提供的第二个链接得到了相同的explosion.ogg文件。我仍然得到这些错误:
A person provided a video on Youtube stating that SoundPool works normally. Video link is given below. I did what the video instructed me to code, I grabbed the same explosion.ogg file I got from the second link provided above. I still get these errors:
5月3日至一十三号:17:10.143:E / AudioTrack(3370):AudioFlinger无法创建跟踪,状态:-12
五月3日至一十三日:17:10.143:E /的Soundpool(3370):错误创建AudioTrack
我不知道的Soundpool存在由于Android 1.0,在API级别1不应该有任何理由的Soundpool到无法工作,甚至当我有证据证明的Soundpool工作(视频链接,第二一个)。
I do know that SoundPool exists since Android 1.0, at API level 1. There shouldn't be any reason for SoundPool to fail to work, even when I have proof that SoundPool works (the video link, 2nd one).
这些是我的发现,可能会或可能不会帮助别人的一个好办法。总之,你不是一个人在这里。
These are my findings and may or may not help others in a good way. In short, you're not alone here.
来源:
- <一个href="http://$c$c.google.com/p/beginning-android-games/source/browse/trunk/ch04-android-basics/src/com/badlogic/androidgames/SoundPoolTest.java">http://$c$c.google.com/p/beginning-android-games/source/browse/trunk/ch04-android-basics/src/com/badlogic/androidgames/SoundPoolTest.java
- <一个href="http://www.youtube.com/watch?v=ioGWpu8Ud7A">http://www.youtube.com/watch?v=ioGWpu8Ud7A
- http://code.google.com/p/beginning-android-games/source/browse/trunk/ch04-android-basics/src/com/badlogic/androidgames/SoundPoolTest.java
- http://www.youtube.com/watch?v=ioGWpu8Ud7A
编辑:我能够从的Soundpool播放声音
I am able to play sounds from SoundPool.
下面是我的code:
package nttu.edu.test;
import nttu.edu.R;
import android.app.Activity;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class SoundPoolTest extends Activity implements OnClickListener {
SoundPool soundPool = null;
int explosionId = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView v = new TextView(this);
v.setOnClickListener(this);
setContentView(v);
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
v.setText("Click anywhere to play the sound.");
}
protected void onResume() {
super.onResume();
if (soundPool == null) {
soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
explosionId = soundPool.load(this, R.raw.explosion, 1);
}
}
protected void onPause() {
super.onPause();
if (soundPool != null) {
soundPool.release();
soundPool = null;
}
}
public void onClick(View v) {
if (explosionId != 0)
soundPool.play(explosionId, 1, 1, 0, 0, 1);
}
}
我所做的是围绕重构我的code。我学会了这个技巧从Youtube视频链接,其中评论的作者流逝ErichLancaster的名称的意见之一。所有学分到他家里去。我希望这有助于你。
What I did was refactor my code around. I learned this tip from one of the comments in the Youtube video link, where the author of the comment goes by the name of "ErichLancaster". All credits go to him. I hoped this helped you out.
我还设置了Android模拟器分辨率大小为QVGA,如果它真的很重要与否。
I also set the Android emulator resolution size to QVGA, if it really matters or not.
这篇关于的Soundpool:错误创建AudioTrack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!