Android 流媒体播放器开发实现
2010-05-26 15:38:00 来源:WEB开发网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();
更多精彩
赞助商链接