Можно ли записать аудио или видео в том месте, где я остановил запись, приостановив его?в iphone SDK - PullRequest
1 голос
/ 31 марта 2011

Можно ли записать аудио или видео в том месте, где я остановил запись, приостановив его?

1 Ответ

0 голосов
/ 14 апреля 2011

HI Monish, возможно для аудио, я пытаюсь в AVAudioRecorded. Я прилагаю код ниже.

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];  
        }];

, используя этот код, чтобы возобновить запись звука.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...