From 47ec461139befa5c9498a42c84a8da1f1a89a2ba Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 18 Jun 2017 19:08:53 +0200 Subject: [PATCH] release the mediaplayer if something goes wrong at init --- .../gallery/fragments/VideoFragment.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt index ebc0acdee..c5a556f82 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -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() {