我想在對話框中播放聲音。在對話框中有一個gif動畫,現在我想在其中放入一個聲音。我正在嘗試這個代碼,但它沒有那麼有用。我只能玩GIF動畫。請幫忙。在對話框中播放聲音
ImageButton bicycle = (ImageButton)findViewById(R.id.imageButton1);
bicycle.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog.Builder builder = new AlertDialog.Builder(Vehicles.this);
WebView view = new WebView(Vehicles.this);
view.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
builder.setView(view);
//builder.create().show();
final Dialog d = builder.create(); // save a Dialog reference here
d.show();
view.loadUrl("file:///android_asset/bicycle.gif");
soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 1);
mMediaPlayer = new MediaPlayer();
mMediaPlayer = MediaPlayer.create(Vehicles.this, R.raw.bicycle);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.start();
soundIsPlaying = true;
new Handler().postDelayed(new Runnable() {
public void run() {
soundIsPlaying = false;
}
}, PLAYING_TIME_OF_SOUND);
gifIsPlaying = true;
new Handler().postDelayed(new Runnable() {
public void run() {
gifIsPlaying = false;
//finish();
if (d.isShowing()) { // dismiss dialog if still showing
d.dismiss();
}
}
}, PLAYING_TIME_OF_GIF);
}
});
任何錯誤...? –
錯誤在這一行「mMediaPlayer = MediaPlayer.create(this,R.raw.bicycle);」 – Meghs
哦,然後發佈logcat太:) –