初学Android开发!求一个完整的详细的Android小程序源码参考!

 我来答
匿名用户
2013-05-21
展开全部
媒体播放器源码Audio.java
package org.example.audio;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.KeyEvent;

public class Audio extends Activity {
private MediaPlayer up, down, left, right, enter;
private MediaPlayer a, s, d, f;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// Native rate is 44.1kHz 16 bit stereo, but
// to save space we just use MPEG-3 22kHz mono
up = MediaPlayer.create(this, R.raw.up);
down = MediaPlayer.create(this, R.raw.down);
left = MediaPlayer.create(this, R.raw.left);
right = MediaPlayer.create(this, R.raw.right);
enter = MediaPlayer.create(this, R.raw.enter);
a = MediaPlayer.create(this, R.raw.a);
s = MediaPlayer.create(this, R.raw.s);
d = MediaPlayer.create(this, R.raw.d);
f = MediaPlayer.create(this, R.raw.f);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
MediaPlayer mp;
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_UP:
mp = up;
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
mp = down;
break;
case KeyEvent.KEYCODE_DPAD_LEFT:
mp = left;
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
mp = right;
break;
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
mp = enter;
break;
case KeyEvent.KEYCODE_A:
mp = a;
break;
case KeyEvent.KEYCODE_S:
mp = s;
break;
case KeyEvent.KEYCODE_D:
mp = d;
break;
case KeyEvent.KEYCODE_F:
mp = f;
break;
default:
return super.onKeyDown(keyCode, event);
}
mp.seekTo(0);
mp.start();
return true;
}

}
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式