安卓播放音频剪辑的onClick [英] Android: Playing an audio clip onClick

查看:130
本文介绍了安卓播放音频剪辑的onClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何建立一个的AudioFile当用户触碰图像播放。

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

我应该在哪里存储音频文件,什么code我应该用实际播放的文件? 我不想调出MediaPlayer的接口或类似的东西。

Where should I store the audio file and what code should I use to actually play the file? I don't want to bring up the MediaPlayer interface or anything like that.

我想这样做是这样的:

foo = (ImageView)this.findViewById(R.id.foo);
    foo.setOnClickListener(this);

public void onClick(View v) {
if (foo.isTouched()) {

 playAudioFile();
  }
}

感谢

推荐答案

这将不会创建一个弹出的MediaPlayer接口......它只会玩你想要的声音。

This won't create a bring up the MediaPlayer interface... it will just play the sound you want.

Button boton = (Button) findViewById(R.id.boton);
boton.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
  MediaPlayer mp = MediaPlayer.create(TestSonido.this, R.raw.slayer);  
  mp.start();
 }
});

在这种情况下, R.raw.slayer 重presents称为音频文件 slayer.mp3 存储在 RES /生/ 文件夹,一旦你点击了按钮,机器人将岩石你...

In this case, R.raw.slayer represents an audio file called slayer.mp3 that is stored in the res/raw/ folder and once you click the button the droid will rock you...

这篇关于安卓播放音频剪辑的onClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆