首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

播发raw中的音乐范例

2013-03-13 
播放raw中的音乐范例package cn.test.lee?import android.app.Serviceimport android.content.Intentim

播放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;

?

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();

}

?

}

热点排行