33
44@implementation Audio
55
6- static Action onAudioSessionRouteChangedEvent;
76static Action audioSessionRouteChangedEvent;
7+ static ULongCallback audioInterruptionEvent;
88static BOOL inited;
99
10- +(void )Init : (Action)OnAudioSessionRouteChangedCallback
10+ +(void )Init : (Action)audioSessionRouteChangedCallback
11+ audioInterruptionCallback : (ULongCallback)audioInterruptionCallback
1112{
1213 if (inited)
1314 return ;
@@ -16,9 +17,40 @@ +(void)Init:(Action)OnAudioSessionRouteChangedCallback
1617 selector: @selector (OnAudioSessionRouteChanged: )
1718 name: AVAudioSessionRouteChangeNotification
1819 object: nil ];
20+
21+ audioInterruptionEvent = audioInterruptionCallback;
22+ [[NSNotificationCenter defaultCenter ] addObserver: [Audio class ]
23+ selector: @selector (OnAudioInterruptionEvent: )
24+ name: AVAudioSessionInterruptionNotification
25+ object: nil ];
1926 inited = YES ;
2027}
2128
29+ // static BOOL audioInterrupted;
30+
31+
32+ +(void )OnAudioInterruptionEvent : (NSNotification *)notification
33+ {
34+ auto userInfo = notification.userInfo ;
35+ auto typeValue = [userInfo[AVAudioSessionInterruptionTypeKey] unsignedIntegerValue ];
36+ auto type = (AVAudioSessionInterruptionType)typeValue;
37+
38+ // audioInterrupted = type == AVAudioSessionInterruptionTypeBegan;
39+
40+ /* switch (type) {
41+ case AVAudioSessionInterruptionTypeBegan:
42+ audioInterrupted = true;
43+ break;
44+
45+ default:
46+ audioInterrupted = false;
47+ break;
48+ }*/
49+
50+ if (audioInterruptionEvent != nil )
51+ audioInterruptionEvent (typeValue);
52+ }
53+
2254+(void )OnAudioSessionRouteChanged : (NSNotification *)notification
2355{
2456 if (audioSessionRouteChangedEvent != nil )
0 commit comments