@@ -30,6 +30,7 @@ export class AudioFocusManager extends Observable {
3030 private _mAudioFocusGranted : boolean = false ;
3131 private _durationHint : AudioFocusDurationHint ;
3232 private _audioPlayerSet = new Set < TNSPlayer > ( ) ;
33+ private _mOnAudioFocusChangeListener : android . media . AudioManager . OnAudioFocusChangeListener ;
3334
3435 constructor ( options ?: AudioFocusManagerOptions ) {
3536 super ( ) ;
@@ -41,23 +42,23 @@ export class AudioFocusManager extends Observable {
4142 // Request audio focus for play back
4243
4344 const playbackAttributes = new android . media . AudioAttributes . Builder ( ) . setUsage ( options . usage ) . setContentType ( options . contentType ) . build ( ) ;
45+ const that = new WeakRef ( this ) ;
46+ this . _mOnAudioFocusChangeListener = new android . media . AudioManager . OnAudioFocusChangeListener ( {
47+ onAudioFocusChange : ( focusChange : number ) => {
48+ that ?. get ( ) ?. notify ( {
49+ eventName : 'audioFocusChange' ,
50+ object : this ,
51+ focusChange
52+ } ) ;
53+ }
54+ } ) ;
4455 this . _audioFocusRequest = new android . media . AudioFocusRequest . Builder ( options . durationHint )
4556 . setAudioAttributes ( playbackAttributes )
4657 . setAcceptsDelayedFocusGain ( true )
4758 . setOnAudioFocusChangeListener ( this . _mOnAudioFocusChangeListener )
4859 . build ( ) ;
4960 }
5061
51- private _mOnAudioFocusChangeListener = new android . media . AudioManager . OnAudioFocusChangeListener ( {
52- onAudioFocusChange : ( focusChange : number ) => {
53- this . notify ( {
54- eventName : 'audioFocusChange' ,
55- object : this ,
56- focusChange
57- } ) ;
58- }
59- } ) ;
60-
6162 private needsFocus ( ) : boolean {
6263 return this . _audioPlayerSet . size > 0 ;
6364 }
0 commit comments