1
1
/// <reference path="./native-definitions/libvlc-service.d.ts" />
2
2
3
- import { CommonAudioPlayer , MediaTrack , Playlist , PlaybackEvent } from './audioplayer.common' ;
4
3
import * as app from 'tns-core-modules/application' ;
4
+ import { CommonAudioPlayer , MediaTrack , PlaybackEvent , Playlist } from './audioplayer.common' ;
5
5
6
- export { MediaTrack , Playlist , PlaybackEvent } from './audioplayer.common' ;
6
+ export { MediaTrack , PlaybackEvent , Playlist } from './audioplayer.common' ;
7
7
8
8
interface TNSConnectionCallback {
9
9
isConnected : boolean ;
10
10
}
11
- let TNSConnectionCallback : new ( owner : WeakRef < TNSAudioPlayer > ,
12
- resolve : ( value ?: any ) => void ,
13
- reject : ( reason ?: any ) => void ) => dk . nota . lyt . libvlc . ConnectionCallback ;
11
+
12
+ let TNSConnectionCallback : new (
13
+ owner : WeakRef < TNSAudioPlayer > ,
14
+ resolve : ( value ?: any ) => void ,
15
+ reject : ( reason ?: any ) => void ,
16
+ ) => dk . nota . lyt . libvlc . ConnectionCallback ;
14
17
15
18
function ensureTNSConnectionCallback ( ) {
16
19
if ( TNSConnectionCallback ) {
@@ -19,11 +22,9 @@ function ensureTNSConnectionCallback() {
19
22
20
23
@Interfaces ( [ dk . nota . lyt . libvlc . ConnectionCallback ] )
21
24
class TNSConnectionCallbackImpl extends java . lang . Object {
22
-
23
- constructor ( private owner : WeakRef < TNSAudioPlayer > ,
24
- private resolve : ( value ?: any ) => void ,
25
- private reject : ( reason ?: any ) => void ) {
25
+ constructor ( private owner : WeakRef < TNSAudioPlayer > , private resolve : ( value ?: any ) => void , private reject : ( reason ?: any ) => void ) {
26
26
super ( ) ;
27
+
27
28
return global . __native ( this ) ;
28
29
}
29
30
@@ -47,8 +48,7 @@ function ensureTNSConnectionCallback() {
47
48
TNSConnectionCallback = TNSConnectionCallbackImpl ;
48
49
}
49
50
50
- export class TNSAudioPlayer extends CommonAudioPlayer
51
- {
51
+ export class TNSAudioPlayer extends CommonAudioPlayer {
52
52
public service : dk . nota . lyt . libvlc . PlaybackService ;
53
53
54
54
private _serviceHelper : dk . nota . lyt . libvlc . PlaybackServiceHelper ;
@@ -73,16 +73,16 @@ export class TNSAudioPlayer extends CommonAudioPlayer
73
73
}
74
74
75
75
public onConnected ( service : dk . nota . lyt . libvlc . PlaybackService ) {
76
- this . _log ( " PlaybackService - Connected" ) ;
76
+ this . _log ( ' PlaybackService - Connected' ) ;
77
77
this . setupServiceCallbacks ( service ) ;
78
78
this . service = service ;
79
79
if ( service . getMediaListIdentifier ( ) ) {
80
- this . _log ( " - existing playlist ID: " + service . getMediaListIdentifier ( ) ) ;
80
+ this . _log ( ' - existing playlist ID: ' + service . getMediaListIdentifier ( ) ) ;
81
81
}
82
82
}
83
83
84
84
public onDisconnected ( ) {
85
- this . _log ( " PlaybackService - Disconnected" ) ;
85
+ this . _log ( ' PlaybackService - Disconnected' ) ;
86
86
// NOTE: avoid recursive onDisconnected calls
87
87
if ( ! this . service ) {
88
88
return ;
@@ -94,7 +94,7 @@ export class TNSAudioPlayer extends CommonAudioPlayer
94
94
}
95
95
96
96
private setupServiceCallbacks ( service : dk . nota . lyt . libvlc . PlaybackService ) {
97
- service . setNotificationActivity ( app . android . startActivity , " LAUNCHED_FROM_NOTIFICATION" ) ;
97
+ service . setNotificationActivity ( app . android . startActivity , ' LAUNCHED_FROM_NOTIFICATION' ) ;
98
98
service . removeAllCallbacks ( ) ;
99
99
service . addCallback ( this . lytPlaybackEventHandler ) ;
100
100
}
@@ -121,7 +121,7 @@ export class TNSAudioPlayer extends CommonAudioPlayer
121
121
mediaList . add ( this . getNewMediaWrapper ( track ) ) ;
122
122
}
123
123
this . service . load ( mediaList ) ;
124
- this . _log ( 'Set playlist identifier = ' + playlist . UID ) ;
124
+ this . _log ( 'Set playlist identifier = ' + playlist . UID ) ;
125
125
this . service . setMediaListIdentifier ( playlist . UID ) ;
126
126
}
127
127
}
@@ -257,64 +257,64 @@ export class TNSAudioPlayer extends CommonAudioPlayer
257
257
}
258
258
259
259
private lytPlaybackEventHandler = new dk . nota . lyt . libvlc . PlaybackEventHandler ( {
260
- update : ( ) => {
261
- // this._log('update');
262
- } ,
263
- updateProgress : ( ) => {
264
- // this._log('progress');
265
- } ,
266
- onMediaEvent : ( event : dk . nota . lyt . libvlc . media . MediaEvent ) => {
267
- // this._log('mediaEvent: '+ event.type);
268
- if ( event . type == dk . nota . lyt . libvlc . media . MediaEvent . MetaChanged ) {
269
- // this._log('^ MetaChanged ==');
270
- } else if ( event . type == dk . nota . lyt . libvlc . media . MediaEvent . ParsedChanged ) {
271
- // this._log('^ ParsedChanged ==');
272
- } else if ( event . type == dk . nota . lyt . libvlc . media . MediaEvent . StateChanged ) {
273
- // this._log('^ StateChanged ==');
260
+ update : ( ) => {
261
+ // this._log('update');
262
+ } ,
263
+ updateProgress : ( ) => {
264
+ // this._log('progress');
265
+ } ,
266
+ onMediaEvent : ( event : dk . nota . lyt . libvlc . media . MediaEvent ) => {
267
+ // this._log('mediaEvent: '+ event.type);
268
+ if ( event . type == dk . nota . lyt . libvlc . media . MediaEvent . MetaChanged ) {
269
+ // this._log('^ MetaChanged ==');
270
+ } else if ( event . type == dk . nota . lyt . libvlc . media . MediaEvent . ParsedChanged ) {
271
+ // this._log('^ ParsedChanged ==');
272
+ } else if ( event . type == dk . nota . lyt . libvlc . media . MediaEvent . StateChanged ) {
273
+ // this._log('^ StateChanged ==');
274
+ }
275
+ } ,
276
+ onMediaPlayerEvent : ( event : dk . nota . lyt . libvlc . media . MediaPlayerEvent ) => {
277
+ const PlayerEvent = dk . nota . lyt . libvlc . media . MediaPlayerEvent ;
278
+ //TODO: Simplify: VLCToClientEventMap
279
+ if ( event . type == PlayerEvent . SeekableChanged ) {
280
+ if ( event . getSeekable ( ) == true && this . _queuedSeekTo !== null ) {
281
+ this . _log ( 'Executing queued SeekTo: ' + this . _queuedSeekTo ) ;
282
+ this . seekTo ( this . _queuedSeekTo ) ;
283
+ this . _queuedSeekTo = null ;
274
284
}
275
- } ,
276
- onMediaPlayerEvent : ( event : dk . nota . lyt . libvlc . media . MediaPlayerEvent ) => {
277
- const PlayerEvent = dk . nota . lyt . libvlc . media . MediaPlayerEvent ;
278
- //TODO: Simplify: VLCToClientEventMap
279
- if ( event . type == PlayerEvent . SeekableChanged ) {
280
- if ( event . getSeekable ( ) == true && this . _queuedSeekTo !== null ) {
281
- this . _log ( 'Executing queued SeekTo: ' + this . _queuedSeekTo ) ;
282
- this . seekTo ( this . _queuedSeekTo ) ;
283
- this . _queuedSeekTo = null ;
284
- }
285
- } else if ( event . type == PlayerEvent . PausableChanged ) {
286
- } else if ( event . type == PlayerEvent . TimeChanged ) {
287
- this . _onPlaybackEvent ( PlaybackEvent . TimeChanged , event . getTimeChanged ( ) ) ;
288
- } else if ( event . type == PlayerEvent . MediaChanged ) {
289
- } else if ( event . type == PlayerEvent . Opening ) {
290
- this . _onPlaybackEvent ( PlaybackEvent . Buffering ) ;
291
- } else if ( event . type == PlayerEvent . Playing ) {
292
- this . _onPlaybackEvent ( PlaybackEvent . Playing ) ;
293
- } else if ( event . type == PlayerEvent . Paused ) {
294
- this . _onPlaybackEvent ( PlaybackEvent . Paused ) ;
295
- } else if ( event . type == PlayerEvent . Stopped ) {
296
- this . _onPlaybackEvent ( PlaybackEvent . Stopped ) ;
297
- } else if ( event . type == PlayerEvent . EndReached ) {
298
- this . _onPlaybackEvent ( PlaybackEvent . EndOfTrackReached ) ;
299
- if ( this . getCurrentPlaylistIndex ( ) >= this . playlist . length - 1 ) {
300
- this . _onPlaybackEvent ( PlaybackEvent . EndOfPlaylistReached ) ;
301
- }
302
- } else if ( event . type == PlayerEvent . SleepTimerChanged ) {
303
- this . _onPlaybackEvent ( PlaybackEvent . SleepTimerChanged ) ;
304
- } else if ( event . type == PlayerEvent . WaitingForNetwork ) {
305
- this . _onPlaybackEvent ( PlaybackEvent . WaitingForNetwork ) ;
306
- } else if ( event . type == PlayerEvent . Buffering ) {
307
- // This only tells % of the buffer-size required to start playback
308
- //this._onPlaybackEvent(PlaybackEvent.Buffering, event.getBuffering());
309
- } else if ( event . type == PlayerEvent . EncounteredError ) {
310
- this . _log ( 'PlayerEvent.EncounteredError' ) ;
311
- this . _onPlaybackEvent ( PlaybackEvent . EncounteredError ) ;
312
- //throw new Error("Android PlaybackService encountered an error");
313
- } else {
314
- // this._log('^ Unhandled PlayerEvent: '+ event.type);
285
+ } else if ( event . type == PlayerEvent . PausableChanged ) {
286
+ } else if ( event . type == PlayerEvent . TimeChanged ) {
287
+ this . _onPlaybackEvent ( PlaybackEvent . TimeChanged , event . getTimeChanged ( ) ) ;
288
+ } else if ( event . type == PlayerEvent . MediaChanged ) {
289
+ } else if ( event . type == PlayerEvent . Opening ) {
290
+ this . _onPlaybackEvent ( PlaybackEvent . Buffering ) ;
291
+ } else if ( event . type == PlayerEvent . Playing ) {
292
+ this . _onPlaybackEvent ( PlaybackEvent . Playing ) ;
293
+ } else if ( event . type == PlayerEvent . Paused ) {
294
+ this . _onPlaybackEvent ( PlaybackEvent . Paused ) ;
295
+ } else if ( event . type == PlayerEvent . Stopped ) {
296
+ this . _onPlaybackEvent ( PlaybackEvent . Stopped ) ;
297
+ } else if ( event . type == PlayerEvent . EndReached ) {
298
+ this . _onPlaybackEvent ( PlaybackEvent . EndOfTrackReached ) ;
299
+ if ( this . getCurrentPlaylistIndex ( ) >= this . playlist . length - 1 ) {
300
+ this . _onPlaybackEvent ( PlaybackEvent . EndOfPlaylistReached ) ;
315
301
}
302
+ } else if ( event . type == PlayerEvent . SleepTimerChanged ) {
303
+ this . _onPlaybackEvent ( PlaybackEvent . SleepTimerChanged ) ;
304
+ } else if ( event . type == PlayerEvent . WaitingForNetwork ) {
305
+ this . _onPlaybackEvent ( PlaybackEvent . WaitingForNetwork ) ;
306
+ } else if ( event . type == PlayerEvent . Buffering ) {
307
+ // This only tells % of the buffer-size required to start playback
308
+ //this._onPlaybackEvent(PlaybackEvent.Buffering, event.getBuffering());
309
+ } else if ( event . type == PlayerEvent . EncounteredError ) {
310
+ this . _log ( 'PlayerEvent.EncounteredError' ) ;
311
+ this . _onPlaybackEvent ( PlaybackEvent . EncounteredError ) ;
312
+ //throw new Error("Android PlaybackService encountered an error");
313
+ } else {
314
+ // this._log('^ Unhandled PlayerEvent: '+ event.type);
316
315
}
317
- } ) ;
316
+ } ,
317
+ } ) ;
318
318
319
319
private isServiceRunning ( serviceClassName : string ) {
320
320
const manager : android . app . ActivityManager = app . android . context . getSystemService ( android . content . Context . ACTIVITY_SERVICE ) ;
0 commit comments