android中选择播放raw内的音乐,播放raw中的音乐范例
package cn.test.lee;import android.app.Service;import android.content.Intent;import android.media.AudioManager;import android.media.MediaPlayer;import android.os.Bundle;import android.os.IBinder;publi
package cn.test.lee;
import android.app.Service;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.IBinder;
public class MyPlayerService extends Service implements
MediaPlayer.OnPreparedListener {
private MediaPlayer mp1;
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onStart(Intent intent, int startId) {
//mp1 = new MediaPlayer();
mp1 = MediaPlayer.create(this, R.raw.ai);
//mp1.reset();
mp1.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
//Bundle b = intent.getExtras();
//String videoPath = b.getString("videoPath");// "/mnt/sdcard/Video/Nobody.mp4";
//
//mp1.setDataSource(videoPath);// "/mnt/sdcard/Video/Nobody.mp4"
H264B3.3gp iceage.avi
test_h263.mp4 /sdcard/test.mp4
mp1.start();
//mp1.setOnPreparedListener(this);
} catch (Exception me) {
}
super.onStart(intent, startId);
}
@Override
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.start();
}
@Override
public void onDestroy() {
mp1.release();
mp1 = null;
super.onDestroy();
}
}
更多推荐
所有评论(0)