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

Android 流媒体播放器开发实现

 2010-05-26 15:38:00 来源:WEB开发网   
核心提示:dealWithLastData();// 删除临时文件if (DLTempFile != null && DLTempFile.exists()) {DLTempFile.delete();}}} catch (MalformedURLException e) {Log.e(TAG, e.toString());}

dealWithLastData();

// 删除临时文件

if (DLTempFile != null && DLTempFile.exists()) {

DLTempFile.delete();

}

}

} catch (MalformedURLException e) {

Log.e(TAG, e.toString());

} catch (IOException e) {

Log.e(TAG, e.toString());

} finally {

if (out != null) {

try {

out.close();

} catch (IOException e) {

e.printStackTrace();

}

}

if (is != null) {

try {

is.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

}

private boolean downloadOver = false;

private boolean wasPlayed = false;

private void dealWithBufferData() {

if (mPlayer == null || !wasPlayed) {

if (totalKbRead >= MIN_BUFF) {

try {

startMediaPlayer();

} catch (Exception e) {

}

}

} else if (mPlayer.getDuration() - mPlayer.getCurrentPosition() <= 1000) {

deleteTempFile(true);

transferBufferToMediaPlayer();

}

}

private void startMediaPlayer() {

try {

deleteTempFile(true);

BUFFTempFile = File.createTempFile(TEMP_BUFF_FILE_NAME,

FILE_POSTFIX);

FileSystemUtil.copyFile(DLTempFile, BUFFTempFile);

mPlayer = new MediaPlayer();

setListener();

mPlayer.setDataSource(BUFFTempFile.getAbsolutePath());

mPlayer.prepare();

mPlayer.start();

wasPlayed = true;

} catch (IOException e) {

}

}

private void transferBufferToMediaPlayer() {

try {

boolean wasPlaying = mPlayer.isPlaying();

int curPosition = mPlayer.getCurrentPosition();

上一页  1 2 3 4 5  下一页

Tags:Android 流媒体 播放器

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