release the mediaplayer if something goes wrong at init
This commit is contained in:
parent
99f14bfee1
commit
47ec461139
1 changed files with 8 additions and 4 deletions
|
@ -229,6 +229,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
}
|
}
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
Log.e(TAG, "init media player failed $e")
|
Log.e(TAG, "init media player failed $e")
|
||||||
|
releaseMediaPlayer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,12 +260,16 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
private fun cleanup() {
|
private fun cleanup() {
|
||||||
pauseVideo()
|
pauseVideo()
|
||||||
mCurrTimeView?.text = 0.getFormattedDuration()
|
mCurrTimeView?.text = 0.getFormattedDuration()
|
||||||
mMediaPlayer?.release()
|
releaseMediaPlayer()
|
||||||
mMediaPlayer = null
|
|
||||||
mSeekBar?.progress = 0
|
mSeekBar?.progress = 0
|
||||||
mTimerHandler?.removeCallbacksAndMessages(null)
|
mTimerHandler?.removeCallbacksAndMessages(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun releaseMediaPlayer() {
|
||||||
|
mMediaPlayer?.release()
|
||||||
|
mMediaPlayer = null
|
||||||
|
}
|
||||||
|
|
||||||
private fun videoPrepared(mediaPlayer: MediaPlayer) {
|
private fun videoPrepared(mediaPlayer: MediaPlayer) {
|
||||||
mDuration = mediaPlayer.duration / 1000
|
mDuration = mediaPlayer.duration / 1000
|
||||||
addPreviewImage()
|
addPreviewImage()
|
||||||
|
@ -295,8 +300,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun surfaceDestroyed(holder: SurfaceHolder) {
|
override fun surfaceDestroyed(holder: SurfaceHolder) {
|
||||||
mMediaPlayer?.release()
|
releaseMediaPlayer()
|
||||||
mMediaPlayer = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setVideoSize() {
|
private fun setVideoSize() {
|
||||||
|
|
Loading…
Reference in a new issue