Use nullable controller var

This commit is contained in:
Naveen 2023-08-27 11:41:50 +05:30
parent e1f4da1bf5
commit 1d6ab55d79
No known key found for this signature in database
GPG key ID: 0E155DAD31671DA3

View file

@ -20,7 +20,7 @@ class SimpleMediaController(val context: Application) {
} }
private lateinit var controllerFuture: ListenableFuture<MediaController> private lateinit var controllerFuture: ListenableFuture<MediaController>
private lateinit var controller: MediaController private var controller: MediaController? = null
@Synchronized @Synchronized
fun createControllerAsync() { fun createControllerAsync() {
@ -30,7 +30,7 @@ class SimpleMediaController(val context: Application) {
.buildAsync() .buildAsync()
controllerFuture.addListener({ controllerFuture.addListener({
controller = getControllerSync()!! controller = getControllerSync()
}, MoreExecutors.directExecutor()) }, MoreExecutors.directExecutor())
} }
@ -61,7 +61,8 @@ class SimpleMediaController(val context: Application) {
} }
fun withController(callback: MediaController.() -> Unit) { fun withController(callback: MediaController.() -> Unit) {
if (::controller.isInitialized && controller.isConnected) { val controller = controller
if (controller != null && controller.isConnected) {
controller.runOnPlayerThread(callback) controller.runOnPlayerThread(callback)
} else { } else {
acquireController { acquireController {