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.video.VideoListener
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.gallery.pro.R
import com.simplemobiletools.gallery.pro.extensions.*
import com.simplemobiletools.gallery.pro.helpers.*
@ -624,11 +623,11 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
}
private fun releaseExoPlayer() {
mExoPlayer?.stop()
ensureBackgroundThread {
mExoPlayer?.release()
mExoPlayer = null
mExoPlayer?.apply {
stop()
release()
}
mExoPlayer = null
}
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
@ -660,9 +659,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
override fun onSurfaceTextureDestroyed(surface: SurfaceTexture) = false
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) {}

View File

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