1

簡単なメモ: SoundPool クラスを使用しています

http://developer.android.com/reference/android/media/SoundPool.html

ここにあるのは、押している間ループ サウンドを再生する単純なボタンです。それはうまくいきます。ただし、sounds.autoPause();API 8まで導入されなかったので、カップケーキと互換性のあるものが本当に必要です(API 3)。API 3のものでフィルタリングされた開発リファレンスサイトを調べていたところ、一時停止していたので、試してみようと思いましsounds.pause(sound);たが、そうではありません手を離しても音を止めないでください。(使い方が間違っているだけでしょうか?) カップケーキに優しい方法でこの音を止める方法を知っている人はいますか? ありがとう!

編集:それもsounds.stop(sound);うまくいきませんでした。

コード:

私のonCreate:

sounds = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
sound = sounds.load(this.getApplicationContext(), R.raw.red_long_one, 1);

次に、ここに私のタッチイベントがあります

@Override public boolean onTouch(View arg0, MotionEvent event) {

            switch (event.getAction() ) { 
            case MotionEvent.ACTION_DOWN: 
                System.out.println("touch");
                sounds.play(sound, 1, 1, 1, -1, 1);
                break;
            case MotionEvent.ACTION_UP:
                System.out.println("up");
                //autoPause does not work on anything lower than sdk8
                sounds.autoPause();
                break; 
            }

            return false;
        }

なぜsounds.stop(sound);機能しないように見えるのか理解できませんが、それは私が読んだ記事で推奨されていることです

sounds.stop(sound);1回使用すると、その後は離しても止まらないことに注意してください。しかし、最初のプレスとリリースは意図したとおりに機能します。

今、andoirdサイトでsoundIDではなくstreamIDと表示されていることは知っていますが、streamIDを取得する方法がわかりません

4

1 に答える 1

1

you need to use streamID to stop a sound. streamID is returned by play():

something like that:

//record streamid when you play a sound streamIDSoundFX=soundPool.play(soundFXPoolMap.get(ctSoundFX), streamVolume, streamVolume, 1, 0, 1f);

//stop it when you need soundPool.stop(streamIDSoundFX);

于 2010-11-04T02:01:16.637 に答える