@@ -176,40 +176,45 @@ export namespace dk {
176
176
return this . _playlist ?. tracks ?. [ index ] ;
177
177
}
178
178
179
+ private lastPosition : number ;
180
+ private lastWindowIndex : number ;
181
+ private _handleTimeChange ( ) {
182
+ const player = this . exoPlayer ;
183
+ if ( ! player ) {
184
+ if ( trace . isEnabled ( ) ) {
185
+ trace . write ( `${ this . cls } ._onPlaying() - no player stop timeChangeInterval` , notaAudioCategory ) ;
186
+ }
187
+
188
+ clearInterval ( this . _timeChangeInterval ) ;
189
+
190
+ return ;
191
+ }
192
+
193
+ const windowIndex = player . getCurrentWindowIndex ( ) ;
194
+ let position = player . getCurrentPosition ( ) ;
195
+ const duration = player . getDuration ( ) ;
196
+
197
+ if ( this . lastPosition !== position || this . lastWindowIndex !== windowIndex ) {
198
+ this . owner ?. _onTimeChanged ( position , duration , windowIndex ) ;
199
+
200
+ this . lastPosition = position ;
201
+ this . lastWindowIndex = windowIndex ;
202
+ }
203
+ }
204
+
179
205
public _onPlaying ( ) {
180
206
if ( trace . isEnabled ( ) ) {
181
207
trace . write ( `${ this . cls } ._onPlaying()` , notaAudioCategory ) ;
182
208
}
183
209
clearInterval ( this . _timeChangeInterval ) ;
184
210
185
- let lastCurrentTime : number ;
186
- let lastPlaylistIndex : number ;
187
211
this . _timeChangeInterval = setInterval ( ( ) => {
188
- const exoPlayer = this . exoPlayer ;
189
- if ( ! exoPlayer ) {
190
- if ( trace . isEnabled ( ) ) {
191
- trace . write ( `${ this . cls } ._onPlaying() - no player stop timeChangeInterval` , notaAudioCategory ) ;
192
- }
193
-
194
- clearInterval ( this . _timeChangeInterval ) ;
195
-
196
- return ;
197
- }
198
-
199
- const currentPlaylistIndex = exoPlayer . getCurrentWindowIndex ( ) ;
200
- const currentTime = exoPlayer . getCurrentPosition ( ) ;
201
- const duration = exoPlayer . getDuration ( ) ;
202
-
203
- if ( lastCurrentTime !== currentTime || lastPlaylistIndex !== currentPlaylistIndex ) {
204
- this . owner ?. _onTimeChanged ( currentTime , duration , currentPlaylistIndex ) ;
205
-
206
- lastCurrentTime = currentTime ;
207
- lastPlaylistIndex = currentPlaylistIndex ;
208
- }
212
+ this . _handleTimeChange ( ) ;
209
213
} , 100 ) ;
210
214
211
215
this . _mediaSession ?. setActive ( true ) ;
212
216
217
+ this . _handleTimeChange ( ) ;
213
218
this . owner ?. _onPlaying ( ) ;
214
219
}
215
220
@@ -368,20 +373,13 @@ export namespace dk {
368
373
trace . write ( `${ this . cls } .onStartCommand(${ intent } , ${ flags } , ${ startId } )` , notaAudioCategory ) ;
369
374
}
370
375
371
- if ( android . os . Build . VERSION . SDK_INT >= 24 && this . _mediaSession ) {
376
+ if ( this . _mediaSession ) {
372
377
androidx . media . session . MediaButtonReceiver . handleIntent ( this . _mediaSession , intent ) ;
373
378
}
374
379
375
380
return super . onStartCommand ( intent , flags , startId ) ;
376
381
}
377
382
378
- public onStart ( intent : android . content . Intent , startId : number ) {
379
- if ( trace . isEnabled ( ) ) {
380
- trace . write ( `${ this . cls } .onStart(${ intent } , ${ startId } )` , notaAudioCategory ) ;
381
- }
382
- super . onStart ( intent , startId ) ;
383
- }
384
-
385
383
public setOwner ( owner : TNSAudioPlayer ) {
386
384
if ( trace . isEnabled ( ) ) {
387
385
trace . write ( `${ this . cls } .setOwner()` , notaAudioCategory ) ;
@@ -1164,6 +1162,14 @@ function ensureNativeClasses() {
1164
1162
return global . __native ( this ) ;
1165
1163
}
1166
1164
1165
+ public onNotificationPosted ( notificationId : number , notification : android . app . Notification , ongoing ?: boolean ) {
1166
+ if ( trace . isEnabled ( ) ) {
1167
+ trace . write ( `${ this . cls } .onNotificationPosted(${ notificationId } , ${ notification } , ${ ongoing } )` , notaAudioCategory ) ;
1168
+ }
1169
+
1170
+ this . owner ?. _handleNotificationPosted ( notificationId , notification ) ;
1171
+ }
1172
+
1167
1173
public onNotificationCancelled ( notificationId : number , dismissedByUser ?: boolean ) {
1168
1174
if ( trace . isEnabled ( ) ) {
1169
1175
trace . write ( `${ this . cls } .NotificationListener(id=${ notificationId } , dismissedByUser=${ dismissedByUser } )` , notaAudioCategory ) ;
@@ -1180,26 +1186,6 @@ function ensureNativeClasses() {
1180
1186
1181
1187
this . owner ?. stopSelf ( ) ;
1182
1188
}
1183
- public onNotificationPosted ( notificationId : number , notification : android . app . Notification , ongoing ?: boolean ) {
1184
- if ( trace . isEnabled ( ) ) {
1185
- trace . write ( `${ this . cls } .onNotificationPosted(${ notificationId } , ${ notification } , ${ ongoing } )` , notaAudioCategory ) ;
1186
- }
1187
-
1188
- this . owner ?. _handleNotificationPosted ( notificationId , notification ) ;
1189
- }
1190
-
1191
- public onNotificationStarted ( notificationId : number , notification : android . app . Notification ) {
1192
- // Deprecated
1193
- if ( trace . isEnabled ( ) ) {
1194
- trace . write (
1195
- `${ this . cls } .onNotificationStarted(${ notificationId } , ${ notification } ) is deprecated - why was this called?` ,
1196
- notaAudioCategory ,
1197
- trace . messageType . warn ,
1198
- ) ;
1199
- }
1200
-
1201
- this . owner ?. _handleNotificationPosted ( notificationId , notification ) ;
1202
- }
1203
1189
}
1204
1190
1205
1191
TNSNotificationListener = TNSNotificationListenerImpl ;
0 commit comments