Android: Playing an audio clip onClick

前端 未结 3 870
孤城傲影
孤城傲影 2020-12-08 14:37

How do I set up an audiofile to play when a user touches an image.

Where should I store the audio file and what code should I use to actually play the file? I don\'t

3条回答
  •  离开以前
    2020-12-08 14:44

    public void aud_play(View view) {
      if (!mp.isPlaying()) {   //If media player is not playing it.
    
        mp = MediaPlayer.create(this, R.raw.audio_name);
        mp.start();      
    
      } else {// Toast of Already playing ...
    }
    }
    

提交回复
热议问题