【问题标题】:Jetplayer vs. soundPool?Jetplayer 与 soundPool?
【发布时间】:2013-02-01 09:52:07
【问题描述】:

这是我的主要活动,我相信这就是你所需要的,看看是否有人可以帮助我......

package com.art.drumdrum;

import android.app.Activity;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {
SoundPool soundPool = null;
int kickId = 0;
int snareId = 0;
int crashhId = 0;
int crashlId = 0;
int muteId = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button kick = (Button) findViewById(R.id.kick);
    Button snare = (Button) findViewById(R.id.snare);
    Button crashh = (Button) findViewById(R.id.crashh);
    Button crashl = (Button) findViewById(R.id.crashl);

    kick.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN
                    || event.getAction() == MotionEvent.ACTION_POINTER_DOWN)
                soundPool.play(kickId, 1, 1, 0, 0, 1);
            return false;
        }
    });
    snare.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN
                    || event.getAction() == MotionEvent.ACTION_POINTER_DOWN)
                soundPool.play(snareId, 1, 1, 0, 0, 1);
            return false;
        }
    });
    crashh.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN
                    || event.getAction() == MotionEvent.ACTION_POINTER_DOWN)
                soundPool.play(crashhId, 1, 1, 0, 0, 1);
            return false;
        }
    });
    crashl.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN
                    || event.getAction() == MotionEvent.ACTION_POINTER_DOWN)
                soundPool.play(crashlId, 1, 1, 0, 0, 1);
            return false;
        }
    });

}

protected void onResume() {
    super.onResume();
    if (soundPool == null) {
        soundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
        kickId = soundPool.load(this, R.raw.kick, 1);
        snareId = soundPool.load(this, R.raw.snare, 1);
        crashhId = soundPool.load(this, R.raw.crashh, 1);
        crashlId = soundPool.load(this, R.raw.crashl, 1);
    }
}

protected void onPause() {
    super.onPause();
    if (soundPool != null) {
        soundPool.release();
        soundPool = null;
    }
}

}

我想知道在我尝试做的情况下,使用 JetPlayer 是否会比使用 soundPool 更好。我有它,所以我可以同时按下多个按钮并播放声音,一切看起来都很好,但是从你按下按钮到它播放声音有一点延迟,使它听起来变得不自然......我'几天来一直在查找信息,但没有找到任何帮助,是否有简单的答案,或者它需要更多的代码,甚至可能需要一些 c++?

【问题讨论】:

    标签: android performance android-widget


    【解决方案1】:

    据我所知,JetPlayer 不适合这里,因为它的目标是 MIDI 音频同步。 在 Jet 音频引擎中,您无法在按下按钮时立即播放声音,除非您停止所有之前播放的声音(by JetPlayer#clearQueue())。

    Android 音频延迟问题没有简单的答案。 可能您可以使用 C++ (OpenSL ES) 获得更好的延迟,但我对此知之甚少。 请看相关回答:https://stackoverflow.com/a/12309643

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-10
      • 1970-01-01
      • 2013-08-12
      • 2014-04-29
      • 2011-02-12
      • 1970-01-01
      相关资源
      最近更新 更多