WEB开发网
开发学院手机开发Android 开发 Android 流媒体播放器开发实现 阅读

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

上一页  1 2 3 4 5  下一页

Tags:Android 流媒体 播放器

编辑录入:coldstar [复制链接] [打 印]
赞助商链接