Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-03-2010, 03:00 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: PK
Posts: 27
d4devil is on a distinguished road
Angry Audio Duration problem After being exported by AVAssestExportSession

Hello All,

I have been working on a audio application where a user records the audio and later I have to give user the facility to edit that recorded audio as well. The audio being recorded is in .caf format.. herez the code for the setting em using to record the audio

Code:
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    NSError *err = nil;
    [audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];

    [audioSession setActive:YES error:nil];

    NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];

    [recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleeIMA4 ] forKey:AVFormatIDKey];
    [recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
    [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

    [recordSetting setValue :[NSNumber numberWithInt:128000] forKey:AVEncoderBitRateKey ];
    [recordSetting setValue :[NSNumber numberWithInt:AVAudioQualityMax] forKey:AVEncoderAudioQualityKey ];
I have also developed a function where user can trim an existing audio file by giving the start and end time to create a new audio file. Everything is working fine and audio is being trimmed But after trimming my device/simulator cannot read the duration of the new audio file and displays like -3294323423.9000 etc. Here is the code I am using to trim the audio
Code:
-(IBAction) cutButtonTapped: (id) sender {

// inSeconds and outSeconds are float variables which value is being set using the UISlider

if ((inSeconds > 0) && (outSeconds > 0)) {
    if (inSeconds > outSeconds) {
        NSLog(@"inSeconds should not be greater than outSeconds";
        return;
    }

    CMTime inTime = CMTimeMakeWithSeconds(inSeconds, 600);
    CMTime outTime = CMTimeMakeWithSeconds(outSeconds, 600);
    CMTime duration = CMTimeSubtract(outTime, inTime);
    CMTimeRange editRange = CMTimeRangeMake(inTime, duration);
    NSError *editError = nil;
    // Composition is an AVMutableComposition Object which is already initialized 
    [composition insertTimeRange:editRange
                         ofAsset:sourceAsset
                          atTime:composition.duration 
                           error:&editError];
    if (!editError) {

        timeSlider.maximumValue = 
        CMTimeGetSeconds (composition.duration);
    } else {
        NSLog (@"edit error: %@", editError);
    }

    // reset edit points
    inSeconds = -1;
    outSeconds = -1;
    inLabel.text = @"-:--:--";
    outLabel.text = @"-:--:--";
            [self exportAudio];
}

}
ANd finnally exporting the audio file to url path.

Code:
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:composition
                                                                       presetName:AVAssetExportPresetMediumQuality];
NSLog (@"can export: %@", exportSession.supportedFileTypes);
NSArray *dirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [dirs objectAtIndex:0];
NSString *exportPath = [documentsDirectoryPath stringByAppendingPathComponent:@"newAudio.caf"];
NSLog(@"Doc Path: %@", exportPath);
[[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
NSURL *exportURL = [NSURL fileURLWithPath:exportPath];
exportSession.outputURL = exportURL;
exportSession.outputFileType = @"com.apple.m4a-audio";
NSLog(@"File Types: %@" , exportSession.supportedFileTypes);
[exportSession exportAsynchronouslyWithCompletionHandler:^{
    NSLog (@"status is %d",
           exportSession.status);
    switch (exportSession.status) {
        case AVAssetExportSessionStatusFailed:
        case AVAssetExportSessionStatusCompleted: {
            [self performSelectorOnMainThread:@selector (doPostExportUICleanup:)
                                   withObject:nil
                                waitUntilDone:NO];
            break;
        }
    };
}];
exportProgressView.progress = 0.0;
exportProgressView.hidden = NO;
exportTimer = [NSTimer scheduledTimerWithTimeInterval:0.1
   target:self
 selector:@selector (updateExportProgress:)
 userInfo:exportSession repeats:YES];   

}
Please tell me where I am doing it wrong. Any help will be greatly appreciated and to improve the code any suggestion will also be highly encouraged. I have also posted almost the whole code so that it might help someone else who is looking for the same solution.
d4devil is offline   Reply With Quote
Old 12-04-2010, 03:20 PM   #2 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: PK
Posts: 27
d4devil is on a distinguished road
Default

is there no one who can help me ... guys i really need to solve this issue asap ..
d4devil is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 365
6 members and 359 guests
chemistry, daudrizek, HemiMG, Kirkout, MarkC
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,665
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, daudrizek
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:51 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0