Last active
August 29, 2015 14:06
-
-
Save jchernan/6a20bae45f49b8ff9380 to your computer and use it in GitHub Desktop.
Sample usage of jchernan/TPAACAudioConverter in Objective-C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)convertAudio | |
{ | |
BOOL success = NO; | |
NSError *error = nil; | |
AVAudioSession *session = [AVAudioSession sharedInstance]; | |
NSString *sourcePath = @"<source>" | |
NSString *destinationPath = @"<destination>" | |
// set category of audio session | |
success = [session setCategory:AVAudioSessionCategoryPlayback error:&error]; | |
if (!success) { | |
NSLog(@"Failed to set audio category: %@", [error localizedDescription]); | |
return success; | |
} | |
// activate audio session | |
success = [session setActive:YES error:&error]; | |
if (!success) { | |
NSLog(@"Failed to activate audio session: %@", [error localizedDescription]); | |
return success; | |
} | |
// create converter | |
TPAACAudioConverter *converter = [[TPAACAudioConverter alloc] | |
initWithDelegate:self | |
source:sourcePath | |
destination:destinationPath]; | |
// start conversion | |
[converter start]; | |
return YES; | |
} | |
// TPAACAudioConverterDelegate method | |
- (void)AACAudioConverterDidFinishConversion:(TPAACAudioConverter*)converter | |
{ | |
NSError *error = nil; | |
BOOL success = [[AVAudioSession sharedInstance] setActive:NO error:&error]; | |
if (!success) { | |
NSLog(@"Failed to deactivate audio session: %@", [deactivationError localizedDescription]); | |
} | |
} | |
// TPAACAudioConverterDelegate method | |
- (void)AACAudioConverter:(TPAACAudioConverter*)converter didFailWithError:(NSError*)error | |
{ | |
NSLog(@"Audio conversion failed: %@", [error localizedDescription]); | |
NSError *error = nil; | |
BOOL success = [[AVAudioSession sharedInstance] setActive:NO error:&error]; | |
if (!success) { | |
NSLog(@"Failed to deactivate audio session: %@", [deactivationError localizedDescription]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment