AudioFlinger无法创建曲目,状态:-12;创建AudioTrack时出错 [英] AudioFlinger could not create track, status: -12; Error creating AudioTrack

查看:137
本文介绍了AudioFlinger无法创建曲目,状态:-12;创建AudioTrack时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SoundPool遇到问题,因为它拒绝使用我的.ogg文件.我收到此错误:

AudioFlinger could not create track, status: -12
 Error creating AudioTrack

我找到了与此相关的线程以及(可能的)解决方案

主要找到了解决您这一天的方法!向下滚动!!

我和你在同一条船上.在阅读之前,我必须让您知道我没有提供可以解决此问题的答案.

我已经看到很多关于SoundPool的Stack Overflow主题,但是在Android书籍中,关于Java代码,我还没有看到很多SoundPool问题:

AudioTrack:AudioFlinger无法创建轨道,状态为-12.
SoundPool:创建AudioTrack时出错.

这是从此处提供的Beginning Android 4 Game Development源代码中摘录的代码(请参见下文).您可以在其中找到爆炸文件.(在主干中,找到第4章-Android基础知识的/asset文件夹).您必须单击右侧的查看原始文件"以获取文件.

我所做的就是将源代码直接复制到Eclipse,并将从主干提供的explain.ogg文件添加到我的项目中.我执行了Android模拟器,尝试播放了文件,然后告诉您我仍然收到上面引用的相同Logcat错误.

某人在YouTube上提供了一段视频,指出SoundPool正常工作.视频链接如下.我按照视频指示的方式进行了编码,我获取了从上面提供的第二个链接中获得的爆炸文件.我仍然遇到这些错误:

03-13 05:17:10.143:E/AudioTrack(3370):AudioFlinger无法创建曲目,状态:-12
03-13 05:17:10.143:E/SoundPool(3370):创建AudioTrack时出错

我确实知道SoundPool自Android 1.0起就处于API级别1.即使我有证据证明SoundPool可以正常工作(视频链接,第二个),也应该没有任何理由使SoundPool无法正常工作./p>

这些是我的发现,可能会或可能不会以很好的方式帮助他人.简而言之,您并不孤单.

来源:

  1. http://code.google.com/p/beginning-android-games/source/browse/trunk/ch04-android-basics/src/com/badlogic/androidgames/SoundPoolTest.java
  2. http://www.youtube.com/watch?v=ioGWpu8Ud7A

我能够播放SoundPool中的声音.

这是我的代码:

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);
    }
}

我所做的就是重构我的代码.我是从Youtube视频链接中的一条评论中学到的,该评论的作者的名字叫"ErichLancaster".所有的功劳归他所有.我希望这对您有所帮助.

如果确实很重要,我还将Android模拟器的分辨率大小设置为QVGA.

I am having a problem With SoundPool as it refuses to work with my .ogg files. I am getting this error:

AudioFlinger could not create track, status: -12
 Error creating AudioTrack

I've found a thread concerning this and the (possible) answer is:

Make sure you use .ogg media files with constant bitrate!

Is this the case? If yes - which application to use (Audacity doesn't support .ogg custom export settings). If not - what else could be wrong?

As a side note - before I used MediaPlayer but now I want to play a few sounds parallel.

解决方案

MAJOR EDIT: FOUND A WAY TO FIX YOUR DAY!! SCROLL DOWN BELOW!!

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.

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 could not create track, status -12.
SoundPool: Error creating AudioTrack.

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.

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.

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:

03-13 05:17:10.143: E/AudioTrack(3370): AudioFlinger could not create track, status: -12
03-13 05:17:10.143: E/SoundPool(3370): Error creating AudioTrack

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.

Source:

  1. http://code.google.com/p/beginning-android-games/source/browse/trunk/ch04-android-basics/src/com/badlogic/androidgames/SoundPoolTest.java
  2. http://www.youtube.com/watch?v=ioGWpu8Ud7A

EDIT: I am able to play sounds from SoundPool.

Here's my 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);
    }
}

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.

I also set the Android emulator resolution size to QVGA, if it really matters or not.

这篇关于AudioFlinger无法创建曲目,状态:-12;创建AudioTrack时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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