1

最も奇妙なこと。アニメーションが再生されているときは効果音がクリアに聞こえますが、アニメーションが再生されていないときは効果音が途切れます。コードは次のとおりです。

private void Feedback(boolean success)
{
    Log.d(TAG, "Feedback");
    if(success)
    {
        PlayCreatureSound();
        ShowAnimatedCreature();
    }
    else
    {
        PlayFailedSound();
    }
}

private void PlayCreatureSound()
{
    Log.d(TAG, "PlayCreatureSound");
    AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
      float curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
      float maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
      float leftVolume = curVolume/maxVolume;
      float rightVolume = curVolume/maxVolume;      
    spCreatureVoice.play(iCreatureVoicesId[lastCreature.ordinal()], leftVolume, rightVolume, 1, 0, 1);
}

private void PlayFailedSound()
{
    Log.d(TAG, "PlayFailedSound");
    spCreatureVoice.stop(iCreatureVoicesId[FeedbackCreature.FC_COUNT.ordinal()]);
    AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
      float curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
      float maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
      float leftVolume = curVolume/maxVolume;
      float rightVolume = curVolume/maxVolume;      
    spCreatureVoice.play(iCreatureVoicesId[FeedbackCreature.FC_COUNT.ordinal()], leftVolume, rightVolume, 1, 0, 1);
}

private void ShowAnimatedCreature()
{
    Log.d(TAG, "ShowAnimatedCreature");
    // show the creature
    ibtnShapes[lastTargetLocation].setImageBitmap(bmCreatures[lastCreature.ordinal()]); 
    // animate
    ibtnShapes[lastTargetLocation].startAnimation(rotate[0]);
}

私はすでに試しました:1.ファイルの切り替え2.MediaPlayerの使用3.「spCreatureVoice.stop(...」の削除4.優先度の変更

4

2 に答える 2

0

これはエミュレーターの問題のようです。実際のデバイスで問題が発生していません。

于 2011-11-08T20:04:18.253 に答える
0

FeedbackCreature 構造体の処理方法が原因であるか、停止メソッドにある可能性があります。同時に 2 つの効果音を再生しようとしていますか?

これら 2 つのメソッドは非常に多くのコードを共有しているため、次のように組み合わせることをお勧めします。問題を絞り込むのに役立つ場合があります。

private void Feedback(boolean success)
{
    Log.d(TAG, "Feedback");
    if(success)
    {
        int creatureOrdinal = lastCreature.ordinal();
        PlaySound(creatureOrdinal );
        ShowAnimatedCreature(creatureOrdinal );
    }
    else
    {
        int creatureOrdinal = FeedbackCreature.FC_COUNT.ordinal();
        spCreatureVoice.stop(iCreatureVoicesId[creatureOrdinal]);
        PlaySound(creatureOrdinal);
    }
}


private void PlaySound(int creatureOrdinal)
{
    Log.d(TAG, "PlayCreatureSound");
    AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
      float curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
      float maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
      float leftVolume = curVolume/maxVolume;
      float rightVolume = curVolume/maxVolume;      
    spCreatureVoice.play(iCreatureVoicesId[creatureOrdinal], leftVolume, rightVolume, 1, 0, 1);
}

private void ShowAnimatedCreature(int creatureOrdinal)
{
    Log.d(TAG, "ShowAnimatedCreature");
    // show the creature
    ibtnShapes[lastTargetLocation].setImageBitmap(bmCreatures[creatureOrdinal]); 
    // animate
    ibtnShapes[lastTargetLocation].startAnimation(rotate[0]);
}
于 2011-10-27T16:10:13.393 に答える