mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-06-27 07:32:54 +00:00
PlayerService: simplify nullable calls, getters
This commit is contained in:
parent
0a885492b6
commit
a5813f256a
@ -91,7 +91,7 @@ class PlayerService : MediaBrowserServiceCompat() {
|
|||||||
|
|
||||||
// see https://developer.android.com/training/cars/media#browser_workflow
|
// see https://developer.android.com/training/cars/media#browser_workflow
|
||||||
mediaSession = MediaSessionCompat(this, "MediaSessionPlayerServ")
|
mediaSession = MediaSessionCompat(this, "MediaSessionPlayerServ")
|
||||||
setSessionToken(mediaSession!!.getSessionToken())
|
setSessionToken(mediaSession!!.sessionToken)
|
||||||
sessionConnector = MediaSessionConnector(mediaSession!!)
|
sessionConnector = MediaSessionConnector(mediaSession!!)
|
||||||
sessionConnector!!.setMetadataDeduplicationEnabled(true)
|
sessionConnector!!.setMetadataDeduplicationEnabled(true)
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ class PlayerService : MediaBrowserServiceCompat() {
|
|||||||
TAG,
|
TAG,
|
||||||
(
|
(
|
||||||
"onStartCommand() called with: intent = [" + intent +
|
"onStartCommand() called with: intent = [" + intent +
|
||||||
"], extras = [" + intent.getExtras().toDebugString() +
|
"], extras = [" + intent.extras.toDebugString() +
|
||||||
"], flags = [" + flags + "], startId = [" + startId + "]"
|
"], flags = [" + flags + "], startId = [" + startId + "]"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -150,8 +150,8 @@ class PlayerService : MediaBrowserServiceCompat() {
|
|||||||
// no one already and starting the service in foreground should not create any issues.
|
// no one already and starting the service in foreground should not create any issues.
|
||||||
// If the service is already started in foreground, requesting it to be started
|
// If the service is already started in foreground, requesting it to be started
|
||||||
// shouldn't do anything.
|
// shouldn't do anything.
|
||||||
player!!.UIs().getOpt<NotificationPlayerUi>(NotificationPlayerUi::class.java)
|
player!!.UIs().get(NotificationPlayerUi::class.java)
|
||||||
.ifPresent(Consumer { obj: NotificationPlayerUi? -> obj!!.createNotificationAndStartForeground() })
|
?.createNotificationAndStartForeground()
|
||||||
|
|
||||||
if (playerWasNull && onPlayerStartedOrStopped != null) {
|
if (playerWasNull && onPlayerStartedOrStopped != null) {
|
||||||
// notify that a new player was created (but do it after creating the foreground
|
// notify that a new player was created (but do it after creating the foreground
|
||||||
@ -161,8 +161,8 @@ class PlayerService : MediaBrowserServiceCompat() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Intent.ACTION_MEDIA_BUTTON == intent.getAction() &&
|
if (Intent.ACTION_MEDIA_BUTTON == intent.action &&
|
||||||
(player == null || player!!.getPlayQueue() == null)
|
(player == null || player!!.playQueue == null)
|
||||||
) {
|
) {
|
||||||
/*
|
/*
|
||||||
No need to process media button's actions if the player is not working, otherwise
|
No need to process media button's actions if the player is not working, otherwise
|
||||||
@ -174,16 +174,11 @@ class PlayerService : MediaBrowserServiceCompat() {
|
|||||||
return START_NOT_STICKY
|
return START_NOT_STICKY
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player != null) {
|
val p = player
|
||||||
player!!.handleIntent(intent)
|
if (p != null) {
|
||||||
player!!.UIs().getOpt<MediaSessionPlayerUi>(MediaSessionPlayerUi::class.java)
|
p.handleIntent(intent)
|
||||||
.ifPresent(
|
p.UIs().get(MediaSessionPlayerUi::class.java)
|
||||||
Consumer { ui: MediaSessionPlayerUi? ->
|
?.handleMediaButtonIntent(intent)
|
||||||
ui!!.handleMediaButtonIntent(
|
|
||||||
intent
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return START_NOT_STICKY
|
return START_NOT_STICKY
|
||||||
@ -278,16 +273,16 @@ class PlayerService : MediaBrowserServiceCompat() {
|
|||||||
TAG,
|
TAG,
|
||||||
(
|
(
|
||||||
"onBind() called with: intent = [" + intent +
|
"onBind() called with: intent = [" + intent +
|
||||||
"], extras = [" + intent.getExtras().toDebugString() + "]"
|
"], extras = [" + intent.extras.toDebugString() + "]"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BIND_PLAYER_HOLDER_ACTION == intent.getAction()) {
|
if (BIND_PLAYER_HOLDER_ACTION == intent.action) {
|
||||||
// Note that this binder might be reused multiple times while the service is alive, even
|
// Note that this binder might be reused multiple times while the service is alive, even
|
||||||
// after unbind() has been called: https://stackoverflow.com/a/8794930 .
|
// after unbind() has been called: https://stackoverflow.com/a/8794930 .
|
||||||
return mBinder
|
return mBinder
|
||||||
} else if (SERVICE_INTERFACE == intent.getAction()) {
|
} else if (SERVICE_INTERFACE == intent.action) {
|
||||||
// MediaBrowserService also uses its own binder, so for actions related to the media
|
// MediaBrowserService also uses its own binder, so for actions related to the media
|
||||||
// browser service, pass the onBind to the superclass.
|
// browser service, pass the onBind to the superclass.
|
||||||
return super.onBind(intent)
|
return super.onBind(intent)
|
||||||
@ -297,7 +292,7 @@ class PlayerService : MediaBrowserServiceCompat() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LocalBinder internal constructor(playerService: PlayerService?) : Binder() {
|
class LocalBinder internal constructor(playerService: PlayerService) : Binder() {
|
||||||
private val playerService: WeakReference<PlayerService?>
|
private val playerService: WeakReference<PlayerService?>
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user