make sure exoplayer is being accessed on the same thread.

exoplayer now forces to use a single application thread.
This commit is contained in:
fatih ergin 2023-06-18 23:21:16 +03:00
parent d4eeaf3fdf
commit 71241ca110
2 changed files with 10 additions and 15 deletions

View file

@ -25,7 +25,6 @@ import com.google.android.exoplayer2.upstream.DataSource
import com.google.android.exoplayer2.upstream.DataSpec import com.google.android.exoplayer2.upstream.DataSpec
import com.google.android.exoplayer2.video.VideoListener import com.google.android.exoplayer2.video.VideoListener
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.R
import com.simplemobiletools.gallery.pro.extensions.* import com.simplemobiletools.gallery.pro.extensions.*
import com.simplemobiletools.gallery.pro.helpers.* import com.simplemobiletools.gallery.pro.helpers.*
@ -624,11 +623,11 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
} }
private fun releaseExoPlayer() { private fun releaseExoPlayer() {
mExoPlayer?.stop() mExoPlayer?.apply {
ensureBackgroundThread { stop()
mExoPlayer?.release() release()
mExoPlayer = null
} }
mExoPlayer = null
} }
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
@ -660,10 +659,8 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
override fun onSurfaceTextureDestroyed(surface: SurfaceTexture) = false override fun onSurfaceTextureDestroyed(surface: SurfaceTexture) = false
override fun onSurfaceTextureAvailable(surface: SurfaceTexture, width: Int, height: Int) { override fun onSurfaceTextureAvailable(surface: SurfaceTexture, width: Int, height: Int) {
ensureBackgroundThread {
mExoPlayer?.setVideoSurface(Surface(video_surface!!.surfaceTexture)) mExoPlayer?.setVideoSurface(Surface(video_surface!!.surfaceTexture))
} }
}
override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture, width: Int, height: Int) {} override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture, width: Int, height: Int) {}
} }

View file

@ -753,11 +753,11 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
private fun releaseExoPlayer() { private fun releaseExoPlayer() {
mIsPlayerPrepared = false mIsPlayerPrepared = false
mExoPlayer?.stop() mExoPlayer?.apply {
ensureBackgroundThread { stop()
mExoPlayer?.release() release()
mExoPlayer = null
} }
mExoPlayer = null
} }
override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture, width: Int, height: Int) {} override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture, width: Int, height: Int) {}
@ -767,10 +767,8 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
override fun onSurfaceTextureDestroyed(surface: SurfaceTexture) = false override fun onSurfaceTextureDestroyed(surface: SurfaceTexture) = false
override fun onSurfaceTextureAvailable(surface: SurfaceTexture, width: Int, height: Int) { override fun onSurfaceTextureAvailable(surface: SurfaceTexture, width: Int, height: Int) {
ensureBackgroundThread {
mExoPlayer?.setVideoSurface(Surface(mTextureView.surfaceTexture)) mExoPlayer?.setVideoSurface(Surface(mTextureView.surfaceTexture))
} }
}
private fun setVideoSize() { private fun setVideoSize() {
if (activity == null || mConfig.openVideosOnSeparateScreen) { if (activity == null || mConfig.openVideosOnSeparateScreen) {