AndroidでMediaPlayerクラスを使用しているときに、問題が発生しました。
SoundPoolを提案する前に、サウンドクリップの再生が完了したときに発生するOnCompletionイベントが必要です。そうでない場合は、それを使用します。
したがって、問題は、3つ以上のクリップが同時にアクティブ化されると、最後の2つのイベントのOnCompletionのみを取得し、すべてではないということです。この問題の解決策を知っている人、またはなぜ発生しているのかを知っている人はいますか?
// When the user clicks on the Chicken Image, this Function is called
public void onChickenClicked(View view)
{
// ToastMsg( "You Clicked the Chicken", Toast.LENGTH_SHORT );
// Then play the sound,
mMediaPlayer[CHICKEN] = MediaPlayer.create(MainActivity.this, R.raw.chicken_sound );
// Start playing the sound
mMediaPlayer[CHICKEN].start();
// This is to catch when the sound clip has ended, this will be
// used to stop the animation for the chicken
mMediaPlayer[CHICKEN].setOnCompletionListener( new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
System.err.println("Chicken On Complete");
// Stop the animation of the Chicken here
mAnimation.cancel();
mAnimation.reset();
// Then switch the image back to the original Chicken pic
ImageView imgView = (ImageView) findViewById(R.id.imageViewofChicken);
imgView.setImageResource(R.drawable.chicken);
mMediaPlayer[CHICKEN].reset();
}} );
// Finds the ImageView, replaces the base img with the alternate img, and plays the sound
animatePicture( R.id.imageViewofChicken, R.drawable.chicken_tongue);
}
public void onCowClicked(View view)
{
// ToastMsg( "You Clicked the Cow", Toast.LENGTH_SHORT );
// Then play the sound,
mMediaPlayer[COW] = MediaPlayer.create(MainActivity.this, R.raw.cow_sound );
// Start playing the sound
mMediaPlayer[COW].start();
// This is to catch when the sound clip has ended, this will be
// used to stop the animation for the chicken
mMediaPlayer[COW].setOnCompletionListener( new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
System.err.println("Cow On Complete");
// Stop the animation of the Chicken here
mAnimation.cancel();
mAnimation.reset();
// Then switch the image back to the original Chicken pic
ImageView imgView = (ImageView) findViewById(R.id.imageViewofCow);
imgView.setImageResource(R.drawable.cow);
mMediaPlayer[COW].reset();
}} );
// Finds the ImageView, replaces the base img with the alternate img, and plays the sound
animatePicture( R.id.imageViewofCow, R.drawable.cow_tongue);
}
//there are more but you get it idea here.
すべてのOnCompleteListenersを起動する方法について誰かが何かアイデアがありますか?