1
我使用AVAudioRecorder類用於記錄聲音。可以在一個AVAudioRecorder會話中啓動,暫停,恢復,停止錄音。如果應用程序關閉並重新開始,這是不可能恢復的記錄已經exiisting音頻文件。恢復記錄被釋放
Issues with recording and playing .wav files IOS
請參考我的問題(以前問這裏)來看看我的代碼初始化錄音機。
有沒有可能這樣做?請幫忙!謝謝!
我使用AVAudioRecorder類用於記錄聲音。可以在一個AVAudioRecorder會話中啓動,暫停,恢復,停止錄音。如果應用程序關閉並重新開始,這是不可能恢復的記錄已經exiisting音頻文件。恢復記錄被釋放
Issues with recording and playing .wav files IOS
請參考我的問題(以前問這裏)來看看我的代碼初始化錄音機。
有沒有可能這樣做?請幫忙!謝謝!
我認爲你必須單獨保存錄音文件到您的文檔目錄每個應用程序關閉的時間和應用程序開始後混合所有音頻記錄爲可用。
這裏混合音頻文件的代碼,你的情況,你只需要混合兩個文件,因此需要相應地使用代碼。
-(void)mixAudios
{
//mix all audio files
AVMutableComposition* mixComposition = [AVMutableComposition composition];
AVMutableCompositionTrack *compositionCommentaryTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
for (number of your recordings)
{
AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:[NSURL URLWithString:@"** Recording file Path **"] options:nil];
if(![compositionCommentaryTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioAsset.duration) ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:CMTimeMake(Start time in seconds for each Recoring,1) error:nil])
{
NSLog(@" error: %@"error);
}
}
//save mixed composition as file
AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition
presetName:AVAssetExportPresetPassthrough];
NSString* videoName = @".mov";
NSString* videoPath = [[NSString alloc] initWithFormat:@"%@/%@", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0], videoName];
NSString *exportPath = [NSTemporaryDirectory() stringByAppendingPathComponent:videoName];
if([[NSFileManager defaultManager] fileExistsAtPath:exportPath])
{
[[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
}
NSURL *exportUrl = [NSURL fileURLWithPath:exportPath];
_assetExport.outputFileType = @"com.apple.quicktime-movie";
_assetExport.outputURL = exportUrl;
_assetExport.shouldOptimizeForNetworkUse = YES;
[_assetExport exportAsynchronouslyWithCompletionHandler:
^(void)
{
[_assetExport release];
NSString *path = [NSString stringWithString:[exportUrl path]];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (path)) {
UISaveVideoAtPathToSavedPhotosAlbum (path, nil, nil, nil);
}
}
];
}
謝謝,我得到它的工作! – user1873452 2013-03-08 00:14:08
但它是不可能恢復的只是增強已存在的文件的記錄?即使我找不到可能性,只是不想錯過。 – user1873452 2013-03-08 02:22:28