Skip to content

Commit e2a45bb

Browse files
committed
fix(exo-player): service not start in time
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent d90c162 commit e2a45bb

1 file changed

Lines changed: 27 additions & 26 deletions

File tree

app/src/main/java/com/nextcloud/client/media/BackgroundPlayerService.kt

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,8 @@ class BackgroundPlayerService :
6363
private val seekBackSessionCommand = SessionCommand(SESSION_COMMAND_ACTION_SEEK_BACK, Bundle.EMPTY)
6464
private val seekForwardSessionCommand = SessionCommand(SESSION_COMMAND_ACTION_SEEK_FORWARD, Bundle.EMPTY)
6565

66-
private val seekForward =
67-
CommandButton.Builder(CommandButton.getIconResIdForIconConstant(CommandButton.ICON_SKIP_FORWARD_15))
68-
.setDisplayName(getString(R.string.media_player_seek_forward))
69-
.setSessionCommand(seekForwardSessionCommand)
70-
.setExtras(Bundle().apply { putInt(COMMAND_KEY_COMPACT_VIEW_INDEX, 2) })
71-
.build()
72-
73-
private val seekBackward =
74-
CommandButton.Builder(CommandButton.getIconResIdForIconConstant(CommandButton.ICON_SKIP_BACK_15))
75-
.setDisplayName(getString(R.string.media_player_seek_backward))
76-
.setSessionCommand(seekBackSessionCommand)
77-
.setExtras(Bundle().apply { putInt(COMMAND_KEY_COMPACT_VIEW_INDEX, 0) })
78-
.build()
66+
private lateinit var seekForward: CommandButton
67+
private lateinit var seekBackward: CommandButton
7968

8069
@Inject
8170
lateinit var clientFactory: ClientFactory
@@ -103,11 +92,26 @@ class BackgroundPlayerService :
10392
}
10493
}
10594

95+
@Suppress("DEPRECATION")
10696
override fun onCreate() {
10797
super.onCreate()
10898

10999
MainApp.getAppComponent().inject(this)
110100

101+
seekForward = CommandButton.Builder()
102+
.setDisplayName(getString(R.string.media_player_seek_forward))
103+
.setIconResId(CommandButton.getIconResIdForIconConstant(CommandButton.ICON_SKIP_FORWARD_15))
104+
.setSessionCommand(seekForwardSessionCommand)
105+
.setExtras(Bundle().apply { putInt(COMMAND_KEY_COMPACT_VIEW_INDEX, 2) })
106+
.build()
107+
108+
seekBackward = CommandButton.Builder()
109+
.setDisplayName(getString(R.string.media_player_seek_backward))
110+
.setIconResId(CommandButton.getIconResIdForIconConstant(CommandButton.ICON_SKIP_BACK_15))
111+
.setSessionCommand(seekBackSessionCommand)
112+
.setExtras(Bundle().apply { putInt(COMMAND_KEY_COMPACT_VIEW_INDEX, 0) })
113+
.build()
114+
111115
exoPlayer = ExoPlayer.Builder(this).build()
112116
mediaSession = buildMediaSession(exoPlayer)
113117

@@ -201,27 +205,24 @@ class BackgroundPlayerService :
201205
.build()
202206

203207
private fun buildNotificationProvider() = object : DefaultMediaNotificationProvider(this) {
204-
val icon = if (mediaSession?.player?.isPlaying == true) {
205-
CommandButton.ICON_PAUSE
206-
} else {
207-
CommandButton.ICON_PLAY
208-
}
209-
210-
val displayName = if (mediaSession?.player?.isPlaying == true) {
211-
getString(R.string.media_player_pause)
212-
} else {
213-
getString(R.string.media_player_play)
214-
}
208+
val isPlaying = mediaSession?.player?.isPlaying ?: false
215209

210+
@Suppress("DEPRECATION")
216211
override fun getMediaButtons(
217212
session: MediaSession,
218213
playerCommands: Player.Commands,
219214
customLayout: ImmutableList<CommandButton>,
220215
showPauseButton: Boolean
221216
): ImmutableList<CommandButton> {
222217
val playPauseButton =
223-
CommandButton.Builder(CommandButton.getIconResIdForIconConstant(icon))
224-
.setDisplayName(displayName)
218+
CommandButton.Builder()
219+
.setDisplayName(
220+
if (isPlaying) getString(R.string.media_player_pause)
221+
else getString(R.string.media_player_play)
222+
)
223+
.setIconResId(
224+
if (isPlaying) R.drawable.ic_pause else R.drawable.ic_play_arrow
225+
)
225226
.setPlayerCommand(COMMAND_PLAY_PAUSE)
226227
.setExtras(Bundle().apply { putInt(COMMAND_KEY_COMPACT_VIEW_INDEX, 1) })
227228
.build()

0 commit comments

Comments
 (0)