小编Sid*_*rth的帖子

AVAudioRecorder仅在中断后记录音频

在我使用AVAudioRecorder和AVAudioPlayer录制和播放音频的应用程序中,我遇到了拨打电话的情况.虽然录音正在进行中,但是如果打来电话,则只会录制通话后录制的音频.希望在通话后录制的录音是电话前录制的录音的延续.

我使用AVAudioRecorderDelegate方法跟踪录音机中发生的中断

  • (void)audioRecorderBeginInterruption:(AVAudioRecorder*)avRecorder和
  • (void)audioRecorderEndInterruption:(AVAudioRecorder*)avRecorder.

在我的EndInterruption方法中,我激活了audioSession.

这是我使用的录制代码

- (void)startRecordingProcess
{
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    NSError *err = nil;
    [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&err];
    if(err)
    {
        DEBUG_LOG(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
        return;
    }
    [audioSession setActive:YES error:&err];
    err = nil;
    if(err)
    {
        DEBUG_LOG(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
        return;
    }
    // Record settings for recording the audio
    recordSetting = [[NSDictionary alloc] initWithObjectsAndKeys:
                     [NSNumber numberWithInt:kAudioFormatMPEG4AAC],AVFormatIDKey,
                     [NSNumber numberWithInt:44100],AVSampleRateKey,
                     [NSNumber numberWithInt: 2],AVNumberOfChannelsKey,
                     [NSNumber numberWithInt:16],AVLinearPCMBitDepthKey,
                     [NSNumber numberWithBool:NO],AVLinearPCMIsBigEndianKey, …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c avfoundation avaudiorecorder avaudiosession

6
推荐指数
1
解决办法
2424
查看次数

获取kb的音频文件大小

在我的应用程序中,我有一个以caf和aac格式存储的音频文件.我需要从音频网址获取kb中音频文件的大小.有没有办法达到这个要求?

iphone audio objective-c nsdata avaudioplayer

3
推荐指数
1
解决办法
1611
查看次数

AVAssetExportSession无法在ios5中运行

在我的应用程序中,我使用AVAssetExportSession组合两个音频文件,它在早期的ios版本中工作正常.但在ios5设备中它无法正常工作.我得到的是一个错误

AVAssetExportSessionStatusFailed: Error Domain=AVFoundationErrorDomain Code=-11820 "Cannot Complete Export" UserInfo=0x1df1c0 {NSLocalizedRecoverySuggestion=Try exporting again., NSLocalizedDescription=Cannot Complete Export}
Run Code Online (Sandbox Code Playgroud)

我用于导出的代码如下所示

有没有人遇到过同样的问题?请提供宝贵的建议.我迫切需要解决这个问题..

//Export function to export the combined audios as one.
-(void)exportAudioFile:(AVComposition*)combinedComposition
{
    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:combinedComposition
                                                                           presetName:AVAssetExportPresetPassthrough];
    NSArray *presets =[AVAssetExportSession exportPresetsCompatibleWithAsset:combinedComposition];
    NSLog(@"presets======%@",presets);
    NSLog (@"can export: %@", exportSession.supportedFileTypes);
    NSArray *dirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectoryPath = [dirs objectAtIndex:0];
    exportPath = [documentsDirectoryPath stringByAppendingPathComponent:@"CombinedNew.m4a"];
    [[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
    exportURL = [NSURL fileURLWithPath:exportPath];
    exportSession.outputURL = exportURL;
    exportSession.outputFileType = @"com.apple.m4a-audio";
    exportSession.shouldOptimizeForNetworkUse = YES;
    [exportSession exportAsynchronouslyWithCompletionHandler:^{
        NSLog …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c avfoundation ios5 avassetexportsession

1
推荐指数
1
解决办法
5770
查看次数