release the mediaplayer if something goes wrong at init

This commit is contained in:
tibbi 2017-06-18 19:08:53 +02:00
parent 99f14bfee1
commit 47ec461139

View file

@ -229,6 +229,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
}
} catch (e: IOException) {
Log.e(TAG, "init media player failed $e")
releaseMediaPlayer()
}
}
@ -259,12 +260,16 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
private fun cleanup() {
pauseVideo()
mCurrTimeView?.text = 0.getFormattedDuration()
mMediaPlayer?.release()
mMediaPlayer = null
releaseMediaPlayer()
mSeekBar?.progress = 0
mTimerHandler?.removeCallbacksAndMessages(null)
}
private fun releaseMediaPlayer() {
mMediaPlayer?.release()
mMediaPlayer = null
}
private fun videoPrepared(mediaPlayer: MediaPlayer) {
mDuration = mediaPlayer.duration / 1000
addPreviewImage()
@ -295,8 +300,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
}
override fun surfaceDestroyed(holder: SurfaceHolder) {
mMediaPlayer?.release()
mMediaPlayer = null
releaseMediaPlayer()
}
private fun setVideoSize() {