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