将音频添加到ImageSwitcher

时间:2014-03-12 14:21:34

标签: android imageswitcher

我的第一篇文章。

我可以向ImageSwitcher添加短音频和文字,它会根据图像改变。我想在底部添加一个textview和audio,它将与顶部的图像同时发生变化。

2 个答案:

答案 0 :(得分:0)

在某些事件中播放声音有两种方法:
MediaPlayerSoundPool

做你想做的最简单的方法是:

//loading the sound "MY_SOUND_EFFECT" from the "res/raw" folder  
final MediaPlayer mp = MediaPlayer.create(this, R.raw.MY_SOUND_EFFECT);

//playing the sound (this line goes into your event handler block)  
mp.start();

答案 1 :(得分:-1)

imgswitch.setImageResource(images[0]);
    if(i==0) {prev.setVisibility(View.VISIBLE);
    suara_hewan=MediaPlayer.create(hewan_darat.this,
    suara[0]);
    suara_hewan.start();}

    next.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (i < images.length - 1) {
                i++;
                if (i == images.length - 1) {
                    next.setVisibility(View.INVISIBLE);
                } else {
                    prev.setVisibility(View.VISIBLE);
                }
                suara_hewan = MediaPlayer.create(hewan_darat.this,
                                suara[i]);
                suara_hewan.setVolume(2,5);
                suara_hewan.start();
                imgswitch.setImageResource(images[i]);
            }
        }
    });

    prev.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (i > 0) {
                i--;
                if (i == 0) {
                    prev.setVisibility(View.INVISIBLE);
                } else {
                    next.setVisibility(View.VISIBLE);
                }
                suara_hewan = MediaPlayer.create(hewan_darat.this,
                        suara[i]);
                suara_hewan.setVolume(2,5);
                suara_hewan.start();
                imgswitch.setImageResource(images[i]);
            }