1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
crate::ix!();
pub fn get_routing_change_reason(reason: AVAudioSessionRouteChangeReason) -> *const u8 {
todo!();
/*
switch (reason)
{
case AVAudioSessionRouteChangeReasonNewDeviceAvailable: return "New device available";
case AVAudioSessionRouteChangeReasonOldDeviceUnavailable: return "Old device unavailable";
case AVAudioSessionRouteChangeReasonCategoryChange: return "Category change";
case AVAudioSessionRouteChangeReasonOverride: return "Override";
case AVAudioSessionRouteChangeReasonWakeFromSleep: return "Wake from sleep";
case AVAudioSessionRouteChangeReasonNoSuitableRouteForCategory: return "No suitable route for category";
case AVAudioSessionRouteChangeReasonRouteConfigurationChange: return "Route configuration change";
case AVAudioSessionRouteChangeReasonUnknown:
default: return "Unknown";
}
*/
}
pub fn get_notification_value_for_key(
notification: *mut NSNotification,
key: *mut NSString,
value: &mut NSUInteger) -> bool {
todo!();
/*
if (notification != nil)
{
if (NSDictionary* userInfo = [notification userInfo])
{
if (NSNumber* number = [userInfo objectForKey: key])
{
value = [number unsignedIntegerValue];
return true;
}
}
}
jassertfalse;
return false;
*/
}
lazy_static!{
/*
@interface iOSAudioSessionNative : NSObject
{
@private
aloe::AudioSessionHolder* audioSessionHolder;
};
- (id) init: (aloe::AudioSessionHolder*) holder;
- (void) dealloc;
- (void) audioSessionChangedInterruptionType: (NSNotification*) notification;
- (void) handleMediaServicesReset;
- (void) handleMediaServicesLost;
- (void) handleRouteChange: (NSNotification*) notification;
@end
@implementation iOSAudioSessionNative
- (id) init: (aloe::AudioSessionHolder*) holder
{
self = [super init];
if (self != nil)
{
audioSessionHolder = holder;
auto session = [AVAudioSession sharedInstance];
auto centre = [NSNotificationCenter defaultCenter];
[centre addObserver: self
selector: @selector (audioSessionChangedInterruptionType:)
name: AVAudioSessionInterruptionNotification
object: session];
[centre addObserver: self
selector: @selector (handleMediaServicesLost)
name: AVAudioSessionMediaServicesWereLostNotification
object: session];
[centre addObserver: self
selector: @selector (handleMediaServicesReset)
name: AVAudioSessionMediaServicesWereResetNotification
object: session];
[centre addObserver: self
selector: @selector (handleRouteChange:)
name: AVAudioSessionRouteChangeNotification
object: session];
}
else
{
jassertfalse;
}
return self;
}
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
[super dealloc];
}
- (void) audioSessionChangedInterruptionType: (NSNotification*) notification
{
NSUInteger value;
if (aloe::getNotificationValueForKey (notification, AVAudioSessionInterruptionTypeKey, value))
{
switch ((AVAudioSessionInterruptionType) value)
{
case AVAudioSessionInterruptionTypeBegan:
audioSessionHolder->handleStatusChange (false, "AVAudioSessionInterruptionTypeBegan");
break;
case AVAudioSessionInterruptionTypeEnded:
audioSessionHolder->handleStatusChange (true, "AVAudioSessionInterruptionTypeEnded");
break;
// No default so the code doesn't compile if this enum is extended.
}
}
}
- (void) handleMediaServicesReset
{
audioSessionHolder->handleStatusChange (true, "AVAudioSessionMediaServicesWereResetNotification");
}
- (void) handleMediaServicesLost
{
audioSessionHolder->handleStatusChange (false, "AVAudioSessionMediaServicesWereLostNotification");
}
- (void) handleRouteChange: (NSNotification*) notification
{
NSUInteger value;
if (aloe::getNotificationValueForKey (notification, AVAudioSessionRouteChangeReasonKey, value))
audioSessionHolder->handleRouteChange ((AVAudioSessionRouteChangeReason) value);
}
@end
*/
}