开发者

Is it possible to record the audio or video at where I stopped recording by pausing it? in iphone sdk

Is it possible to record the audio or video at where I stopped recordin开发者_开发百科g by pausing it?


HI Monish, It possible for Audio i try in AVAudioRecorded.I attach code below.

AVMutableComposition* composition = [AVMutableComposition composition];
        AVURLAsset* audioAsset1 = [[AVURLAsset alloc]initWithURL:recorderfileO options:nil];
        AVURLAsset* audioAsset2 = [[AVURLAsset alloc]initWithURL:recorderfile1 options:nil];

        AVMutableCompositionTrack *audioTrack1 = [composition addMutableTrackWithMediaType:AVMediaTypeAudio 
                                                                          preferredTrackID:kCMPersistentTrackID_Invalid];

        [audioTrack1 insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioAsset1.duration)
                             ofTrack:[[audioAsset1 tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]
                              atTime:kCMTimeZero
                               error:&error];
        [audioTrack1 insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioAsset2.duration) 
                             ofTrack:[[audioAsset2 tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] 
                              atTime:audioAsset1.duration
                               error:&error];
        //NSLog(@"tt :%@",audioTrack1);

        AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:composition
                                                                               presetName:AVAssetExportPresetAppleM4A];
        NSLog (@"can export: %@", exportSession.supportedFileTypes);
        //  NSArray *dirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        //      NSLog(@"Dirs : %@",dirs);
        //      NSString *documentsDirectoryPath = [dirs objectAtIndex:0];

        NSString *documentsDirectoryPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];

        NSDate *today = [NSDate date];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        // display in 12HR/24HR (i.e. 11:25PM or 23:25) format according to User Settings
        [dateFormatter setDateFormat:@"HH:mm:ss"];
        NSString *currentTime = [dateFormatter stringFromDate:today];
        [dateFormatter release];
        NSLog(@"Using File called: %@",currentTime);
        NSString * exportPath1 = [NSString stringWithFormat:@"%@.m4a",currentTime];
        exportPath = [documentsDirectoryPath stringByAppendingPathComponent:exportPath1];
        [[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
        NSLog(@"Doc Path: %@", exportPath);
        exportURL = [NSURL fileURLWithPath:exportPath];
        exportSession.outputURL = exportURL;
        NSLog(@"Doc URL: %@",exportURL);
        exportSession.outputFileType = AVFileTypeAppleM4A;
        NSLog(@"File Types: %@" , exportSession.supportedFileTypes);
        [exportSession exportAsynchronouslyWithCompletionHandler:^{
            NSLog (@"status is %d",
                   exportSession.status);
            Play.enabled = NO;
            if (exportSession.status==3) {
                Play.enabled = YES;
            }
            switch (exportSession.status)
            {
                case AVAssetExportSessionStatusFailed:

                case AVAssetExportSessionStatusCompleted:
                {

                    NSFileManager * fm1 = [NSFileManager defaultManager];
                    [fm1 removeItemAtPath:[recorderfile1 path] error:&error];

                    NSFileManager * fm2 = [NSFileManager defaultManager];
                    [fm2 removeItemAtPath:[recorderfileO path] error:&error];
                    recorderfileO = exportURL;

                    break;
                }
            };
            [audioAsset1 release];
            [audioAsset2 release];
            [audioTrack1 release];  
        }];

using this code to resume recorded the audio.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜