Ios 使用AVAssetExportSession进行UIImagePickerController媒体转换后,UIStatusBar变为红色
我正在使用AVAssetExportSession将从UIImagePickerController获取的.MOV视频转换为.mp4格式。转换完成后,我将数据发送到服务器。一切正常,除了状态栏在传输完成后变为红色并出现脉冲。如果我将应用程序放在后台并再次打开,那么状态栏将再次恢复正常状态 我认为这就是导致这种行为的代码:Ios 使用AVAssetExportSession进行UIImagePickerController媒体转换后,UIStatusBar变为红色,ios,objective-c,uiimagepickercontroller,uistatusbar,avassetexportsession,Ios,Objective C,Uiimagepickercontroller,Uistatusbar,Avassetexportsession,我正在使用AVAssetExportSession将从UIImagePickerController获取的.MOV视频转换为.mp4格式。转换完成后,我将数据发送到服务器。一切正常,除了状态栏在传输完成后变为红色并出现脉冲。如果我将应用程序放在后台并再次打开,那么状态栏将再次恢复正常状态 我认为这就是导致这种行为的代码: //I took a video __block NSString *messageType; __block NSData *messageData;
//I took a video
__block NSString *messageType;
__block NSData *messageData;
__block NSString *messageText;
[...]
NSURL *url = [info objectForKey:UIImagePickerControllerMediaURL];
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
NSString *videoPath = nil;
if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality])
{
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetPassthrough];
videoPath = [[NSTemporaryDirectory() stringByAppendingPathComponent:videoDirectory]stringByAppendingPathComponent:tempVideoFileName];
exportSession.outputURL = [NSURL fileURLWithPath:videoPath];
NSLog(@"videopath of your mp4 file = %@",videoPath); // PATH OF YOUR .mp4 FILE
exportSession.outputFileType = AVFileTypeMPEG4;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch ([exportSession status]) {
case AVAssetExportSessionStatusFailed:{
NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);
[picker dismissViewControllerAnimated:YES completion:^{
[SVProgressHUD showErrorWithStatus:[[exportSession error] localizedDescription]];
}];
}
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"Export canceled");
break;
case AVAssetExportSessionStatusCompleted:{
messageData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:videoPath]];
messageText = videoPath;
messageType = kMessageTypeVideo;
// This method sends asynchronously the data to the server
[self sendMediaType:messageType MessageData:messageData MessageText:messageText];
[picker dismissViewControllerAnimated:YES completion:NULL];
}
break;
default:
break;
}
}];
}
有没有办法避免出现红色状态栏,或者至少我应该用什么方法使其消失?结果是UIImagePickerController的录制会话在某种程度上与AVAssetExportSession冲突 在关闭UIImagePicker控制器后,我通过转换视频解决了此问题:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
if (CFStringCompare ((__bridge_retained CFStringRef) mediaType, kUTTypeImage, 0)
== kCFCompareEqualTo) {
[....]
}
else{
//Took a video
NSURL *url = [info objectForKey:UIImagePickerControllerMediaURL];
[picker dismissViewControllerAnimated:YES completion:^{
[self convertAndSendVideo:url];
}];
}
}
-(void)convertAndSendVideo:(NSURL *)url{
__block NSString *messageType;
__block NSData *messageData;
__block NSString *messageText;
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
NSString *videoPath = nil;
if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality])
{
__block AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetPassthrough];
videoPath = [[NSTemporaryDirectory() stringByAppendingPathComponent:videoDirectory]stringByAppendingPathComponent:tempVideoFileName];
exportSession.outputURL = [NSURL fileURLWithPath:videoPath];
NSLog(@"videopath of your mp4 file = %@",videoPath); // PATH OF YOUR .mp4 FILE
exportSession.outputFileType = AVFileTypeMPEG4;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch ([exportSession status]) {
case AVAssetExportSessionStatusFailed:{
NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);
[SVProgressHUD showErrorWithStatus:[[exportSession error] localizedDescription]];
}
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"Export canceled");
break;
case AVAssetExportSessionStatusCompleted:{
messageData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:videoPath]];
messageText = videoPath;
messageType = kMessageTypeVideo;
[self sendMediaType:messageType MessageData:messageData MessageText:messageText];
}
break;
default:
break;
}
}];
}
}
离题了?!伙计们,你们不是认真的吧!