Use nullable controller var
This commit is contained in:
parent
e1f4da1bf5
commit
1d6ab55d79
1 changed files with 4 additions and 3 deletions
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue