Android 流媒体播放器开发实现
2010-05-26 15:38:00 来源:WEB开发网mPlayer.pause();
BUFFTempFile = File.createTempFile(TEMP_BUFF_FILE_NAME,
FILE_POSTFIX);
FileSystemUtil.copyFile(DLTempFile, BUFFTempFile);
mPlayer = new MediaPlayer();
mPlayer.setDataSource(BUFFTempFile.getAbsolutePath());
mPlayer.prepare();
mPlayer.seekTo(curPosition);
boolean atEndOfFile = mPlayer.getDuration()
- mPlayer.getCurrentPosition() <= 1000;
if (wasPlaying || atEndOfFile) {
mPlayer.start();
}
} catch (Exception e) {
}
}
private void dealWithLastData() {
Runnable updater = new Runnable() {
public void run() {
transferBufferToMediaPlayer();
}
};
handler.post(updater);
}
public void onCompletion(MediaPlayer mp) {
if (mHandler != null) {
mHandler.sendEmptyMessage(Preferences.MEDIA_ENDED);
}
}
public boolean onError(MediaPlayer mediaPlayer, int what, int extra) {
if (mediaPlayer != null) {
mediaPlayer.stop();
mediaPlayer.release();
}
if (mHandler != null) {
mHandler.sendEmptyMessage(Preferences.MEDIA_ERROR);
}
return true;
}
public void onBufferingUpdate(MediaPlayer arg0, int percent) {
Log.d(TAG, "onBufferingUpdate called ---> percent:" + percent);
if (mHandler != null) {
mHandler.sendEmptyMessage(Preferences.EMDIA_BUFF_CHANGE);
}
}
private class PlayThread extends Thread {
private String url;
PlayThread(String url) {
this.url = url;
}
public void run() {
if (!URLUtil.isNetworkUrl(url)) {
mPlayer = new MediaPlayer();
setListener();
更多精彩
赞助商链接