由网友(7.薄荷牛奶萌)分享简介:我如何建立一个的AudioFile当用户触碰图像播放。How do I set up an audiofile to play when a user touches an image.我应该在哪里存储音频文件,什么code我应该用实际播放的文件?我不想调出MediaPlayer的接口或类似的东西。Where...
我如何建立一个的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...
相关推荐
最新文章