标签:
import android.media.MediaPlayer; import android.media.MediaPlayer.*; private MediaPlayer mediaPlayer; OnCreate: mediaPlayer = new MediaPlayer(); mediaPlayer.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { // TODO Auto-generated method stub mediaPlayer.stop(); mediaPlayer.release(); } }); mediaPlayer.setOnErrorListener(new OnErrorListener() { @Override public boolean onError(MediaPlayer mp, int what, int extra) { // TODO Auto-generated method stub mediaPlayer.release(); return true; } }); mediaPlayer.setOnPreparedListener(new OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mediaPlayer.start(); } }); try { String path = Environment.getExternalStorageDirectory().getPath().concat("/com.buzz.exhibition/audio/a.mp3"); //Log.i(TAG, path); mediaPlayer.reset(); mediaPlayer.setDataSource(path); mediaPlayer.prepare(); } catch (Exception ex) { Log.i(TAG, ex.toString()); } onDestroy: mediaPlayer.release();
标签:
原文地址:http://www.cnblogs.com/ncore/p/4318049.html