구글링을 통해서 일정사이즈 만큼 버퍼가 차면, PLAY를 시작하고 버퍼링도 계속해서 진행되는 문서를 확인 후 테스트 해보았습니다.
http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/
하지만, 초반에 buffering한 파일(전체 buffering하는 동안 play되는 파일)과 buffering이 완료되면,
mediaPlayer를 pause하고 다시 seekTO를 통해서 다시 재생합니다.
이 때 중요한 건은. pause 후 play하는 동안 순간적인 끊김현상이 존재하게 되는데 어떻게 보안할 수 있을지 문의 드립니다.
그리고 추가적으로 m3u8(playlist)를 사용해서 재생할 수 없나요? 2.3부터 지원한다고 얘기는 들은 것 같은데.
낮은 버전에서 다른 방법으로 play할수 없는지..
private void transferBufferToMediaPlayer() {
try {
// Determine if we need to restart the player after transferring data (e.g. perhaps the user
// pressed pause) & also store the current audio position so we can reset it later.
boolean wasPlaying = mediaPlayer.isPlaying();
int curPosition = mediaPlayer.getCurrentPosition();
mediaPlayer.pause();
// Copy the current buffer file as we can’t download content into the same file that
// the MediaPlayer is reading from.
File bufferedFile = File.createTempFile(“playingMedia”, “.dat”);
FileUtils.copyFile(downloadingMediaFile,bufferedFile);
// Create a new MediaPlayer. We’ve tried reusing them but that seems to result in
// more system crashes than simply creating new ones.
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(bufferedFile.getAbsolutePath());
mediaPlayer.prepare();
mediaPlayer.seekTo(curPosition);
// Restart if at end of prior beuffered content or mediaPlayer was previously playing.
// NOTE: We test for < 1second of data because the media player can stop when there is still
// a few milliseconds of data left to play
boolean atEndOfFile = mediaPlayer.getDuration() – mediaPlayer.getCurrentPosition() <= 1000;
if (wasPlaying || atEndOfFile){
mediaPlayer.start();
}
}catch (Exception e) {
Log.e(getClass().getName(), “Error updating to newly loaded content.”, e);
}
}