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
|
#import "AppDelegate.h"
#include "tinydav.h"
#include "test_sessions.h"
#define LOOP 0
#define RUN_TEST_ALL 0
#define RUN_TEST_SESSIONS 1
@implementation AppDelegate
@synthesize window;
// Querying the current route
-(void)logCurrentRoute {
CFStringRef route;
UInt32 size = sizeof(route);
// Get the name of the current route.
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute,
&size, &route);
NSLog(@"Route is %@", route);
}
void MyPropListener (void* clientData,
AudioSessionPropertyID inID,
UInt32 dataSize,
const void* inData) {
// The inData argument is a CFDictionary containing the reason for the route change and the name of the old route
CFDictionaryRef dict = (CFDictionaryRef)inData;
// Get the reason for the route change
CFNumberRef reason = CFDictionaryGetValue(dict,
CFSTR(kAudioSession_AudioRouteChangeKey_Reason));
// Get the name of the old route
CFStringRef oldRoute = CFDictionaryGetValue(dict,
CFSTR(kAudioSession_AudioRouteChangeKey_OldRoute));
NSLog(@"Reason was %d", [reason intValue]);
NSLog(@"Old route was %@", oldRoute);
}
- (void)beginInterruption {
NSLog(@"beginInterruption");
}
- (void)endInterruption {
NSLog(@"endInterruption");
NSError *error = nil;
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setActive:YES error:&error];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
}
- (void)endInterruptionWithFlags:(NSUInteger)flags {
NSLog(@"endInterruptionWithFlags");
NSError *error = nil;
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setActive:YES error:&error];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
}
- (void)applicationDidFinishLaunching:(UIApplication *)application {
tnet_startup();
tdav_init();
NSError *error = nil;
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setDelegate:self];
[session setActive:YES error:&error];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, MyPropListener, self );
// Override point for customization after application launch
[window makeKeyAndVisible];
}
- (void)applicationWillTerminate:(UIApplication *)application {
tdav_deinit();
tnet_cleanup();
}
- (void)dealloc {
[window release];
[super dealloc];
}
- (IBAction)start:(id)sender {
do{
/* Print copyright information */
printf("Doubango Project\nCopyright (C) 2009-2010 Mamadou Diop \n\n");
#if RUN_TEST_SESSIONS || RUN_TEST_ALL
test_sessions();
#endif
}
while(LOOP);
}
- (IBAction)change:(id)sender {
UISwitch *switchButton = sender;
if ([switchButton isOn]) {
UInt32 override = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof(override), &override );
} else {
// TODO
}
}
@end
|