@@ -79,7 +79,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
79
79
}
80
80
}
81
81
82
- override var playingState = State .IDLE
82
+ override var playingState: State = State .Idle
83
83
@MainThread
84
84
set(value) {
85
85
if (field != value) {
@@ -96,7 +96,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
96
96
val hasChanged = currentVoiceBroadcast != voiceBroadcast
97
97
when {
98
98
hasChanged -> startPlayback(voiceBroadcast)
99
- playingState == State .PAUSED -> resumePlayback()
99
+ playingState == State .Paused -> resumePlayback()
100
100
else -> Unit
101
101
}
102
102
}
@@ -107,7 +107,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
107
107
108
108
override fun stop () {
109
109
// Update state
110
- playingState = State .IDLE
110
+ playingState = State .Idle
111
111
112
112
// Stop and release media players
113
113
stopPlayer()
@@ -129,7 +129,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
129
129
listeners[voiceBroadcast.voiceBroadcastId]?.add(listener) ? : run {
130
130
listeners[voiceBroadcast.voiceBroadcastId] = CopyOnWriteArrayList <Listener >().apply { add(listener) }
131
131
}
132
- listener.onPlayingStateChanged(if (voiceBroadcast == currentVoiceBroadcast) playingState else State .IDLE )
132
+ listener.onPlayingStateChanged(if (voiceBroadcast == currentVoiceBroadcast) playingState else State .Idle )
133
133
listener.onLiveModeChanged(voiceBroadcast == currentVoiceBroadcast)
134
134
}
135
135
@@ -139,11 +139,11 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
139
139
140
140
private fun startPlayback (voiceBroadcast : VoiceBroadcast ) {
141
141
// Stop listening previous voice broadcast if any
142
- if (playingState != State .IDLE ) stop()
142
+ if (playingState != State .Idle ) stop()
143
143
144
144
currentVoiceBroadcast = voiceBroadcast
145
145
146
- playingState = State .BUFFERING
146
+ playingState = State .Buffering
147
147
148
148
observeVoiceBroadcastStateEvent(voiceBroadcast)
149
149
}
@@ -175,13 +175,13 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
175
175
176
176
private fun onPlaylistUpdated () {
177
177
when (playingState) {
178
- State .PLAYING ,
179
- State .PAUSED -> {
178
+ State .Playing ,
179
+ State .Paused -> {
180
180
if (nextMediaPlayer == null && ! isPreparingNextPlayer) {
181
181
prepareNextMediaPlayer()
182
182
}
183
183
}
184
- State .BUFFERING -> {
184
+ State .Buffering -> {
185
185
val nextItem = if (isLiveListening && playlist.currentSequence == null ) {
186
186
// live listening, jump to the last item if playback has not started
187
187
playlist.lastOrNull()
@@ -193,7 +193,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
193
193
startPlayback(nextItem.startTime)
194
194
}
195
195
}
196
- State .IDLE -> Unit // Should not happen
196
+ State .Idle -> Unit // Should not happen
197
197
}
198
198
}
199
199
@@ -213,7 +213,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
213
213
if (sequencePosition > 0 ) {
214
214
mp.seekTo(sequencePosition)
215
215
}
216
- playingState = State .PLAYING
216
+ playingState = State .Playing
217
217
prepareNextMediaPlayer()
218
218
}
219
219
} catch (failure: Throwable ) {
@@ -224,7 +224,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
224
224
}
225
225
226
226
private fun pausePlayback () {
227
- playingState = State .PAUSED // This will trigger a playing state update and save the current position
227
+ playingState = State .Paused // This will trigger a playing state update and save the current position
228
228
if (currentMediaPlayer != null ) {
229
229
currentMediaPlayer?.pause()
230
230
} else {
@@ -234,7 +234,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
234
234
235
235
private fun resumePlayback () {
236
236
if (currentMediaPlayer != null ) {
237
- playingState = State .PLAYING
237
+ playingState = State .Playing
238
238
currentMediaPlayer?.start()
239
239
} else {
240
240
val savedPosition = currentVoiceBroadcast?.voiceBroadcastId?.let { playbackTracker.getPlaybackTime(it) } ? : 0
@@ -247,11 +247,11 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
247
247
voiceBroadcast != currentVoiceBroadcast -> {
248
248
playbackTracker.updatePausedAtPlaybackTime(voiceBroadcast.voiceBroadcastId, positionMillis, positionMillis.toFloat() / duration)
249
249
}
250
- playingState == State .PLAYING || playingState == State .BUFFERING -> {
250
+ playingState == State .Playing || playingState == State .Buffering -> {
251
251
updateLiveListeningMode(positionMillis)
252
252
startPlayback(positionMillis)
253
253
}
254
- playingState == State .IDLE || playingState == State .PAUSED -> {
254
+ playingState == State .Idle || playingState == State .Paused -> {
255
255
stopPlayer()
256
256
playbackTracker.updatePausedAtPlaybackTime(voiceBroadcast.voiceBroadcastId, positionMillis, positionMillis.toFloat() / duration)
257
257
}
@@ -267,15 +267,15 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
267
267
isPreparingNextPlayer = false
268
268
nextMediaPlayer = mp
269
269
when (playingState) {
270
- State .PLAYING ,
271
- State .PAUSED -> {
270
+ State .Playing ,
271
+ State .Paused -> {
272
272
currentMediaPlayer?.setNextMediaPlayer(mp)
273
273
}
274
- State .BUFFERING -> {
274
+ State .Buffering -> {
275
275
mp.start()
276
276
onNextMediaPlayerStarted(mp)
277
277
}
278
- State .IDLE -> stopPlayer()
278
+ State .Idle -> stopPlayer()
279
279
}
280
280
}
281
281
}
@@ -327,10 +327,10 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
327
327
currentVoiceBroadcast?.voiceBroadcastId?.let { voiceBroadcastId ->
328
328
// Start or stop playback ticker
329
329
when (playingState) {
330
- State .PLAYING -> playbackTicker.startPlaybackTicker(voiceBroadcastId)
331
- State .PAUSED ,
332
- State .BUFFERING ,
333
- State .IDLE -> playbackTicker.stopPlaybackTicker(voiceBroadcastId)
330
+ State .Playing -> playbackTicker.startPlaybackTicker(voiceBroadcastId)
331
+ State .Paused ,
332
+ State .Buffering ,
333
+ State .Idle -> playbackTicker.stopPlaybackTicker(voiceBroadcastId)
334
334
}
335
335
// Notify state change to all the listeners attached to the current voice broadcast id
336
336
listeners[voiceBroadcastId]?.forEach { listener -> listener.onPlayingStateChanged(playingState) }
@@ -348,7 +348,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
348
348
// the current voice broadcast is not live (ended)
349
349
mostRecentVoiceBroadcastEvent?.isLive != true -> false
350
350
// the player is stopped or paused
351
- playingState == State .IDLE || playingState == State .PAUSED -> false
351
+ playingState == State .Idle || playingState == State .Paused -> false
352
352
seekPosition != null -> {
353
353
val seekDirection = seekPosition.compareTo(getCurrentPlaybackPosition() ? : 0 )
354
354
val newSequence = playlist.findByPosition(seekPosition)?.sequence
@@ -374,13 +374,13 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
374
374
375
375
private fun onLiveListeningChanged (isLiveListening : Boolean ) {
376
376
// Live has ended and last chunk has been reached, we can stop the playback
377
- if (! isLiveListening && playingState == State .BUFFERING && playlist.currentSequence == mostRecentVoiceBroadcastEvent?.content?.lastChunkSequence) {
377
+ if (! isLiveListening && playingState == State .Buffering && playlist.currentSequence == mostRecentVoiceBroadcastEvent?.content?.lastChunkSequence) {
378
378
stop()
379
379
}
380
380
}
381
381
382
382
private fun onNextMediaPlayerStarted (mp : MediaPlayer ) {
383
- playingState = State .PLAYING
383
+ playingState = State .Playing
384
384
playlist.currentSequence = playlist.currentSequence?.inc()
385
385
currentMediaPlayer = mp
386
386
nextMediaPlayer = null
@@ -427,7 +427,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
427
427
stop()
428
428
} else {
429
429
// Enter in buffering mode and release current media player
430
- playingState = State .BUFFERING
430
+ playingState = State .Buffering
431
431
currentMediaPlayer?.release()
432
432
currentMediaPlayer = null
433
433
}
@@ -462,18 +462,18 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
462
462
val playbackTime = getCurrentPlaybackPosition()
463
463
val percentage = getCurrentPlaybackPercentage()
464
464
when (playingState) {
465
- State .PLAYING -> {
465
+ State .Playing -> {
466
466
if (playbackTime != null && percentage != null ) {
467
467
playbackTracker.updatePlayingAtPlaybackTime(id, playbackTime, percentage)
468
468
}
469
469
}
470
- State .PAUSED ,
471
- State .BUFFERING -> {
470
+ State .Paused ,
471
+ State .Buffering -> {
472
472
if (playbackTime != null && percentage != null ) {
473
473
playbackTracker.updatePausedAtPlaybackTime(id, playbackTime, percentage)
474
474
}
475
475
}
476
- State .IDLE -> {
476
+ State .Idle -> {
477
477
if (playbackTime == null || percentage == null || (playlist.duration - playbackTime) < 50 ) {
478
478
playbackTracker.stopPlayback(id)
479
479
} else {
0 commit comments