【问题标题】:UIStatusBar become red after using AVAssetExportSession for UIImagePickerController media conversion使用 AVAssetExportSession 进行 UIImagePickerController 媒体转换后 UIStatusBar 变红
【发布时间】:2014-10-25 12:30:32
【问题描述】:

我正在使用 AVAssetExportSession 将从 UIImagePickerController 获得的 .MOV 视频转换为 .mp4 格式。转换完成后,我将数据发送到服务器。一切正常,除了状态栏在传输完成后变为红色并闪烁。如果我将应用程序置于后台并再次打开它,则状态栏将再次恢复正常状态。

这就是我认为导致这种行为的一段代码:

 //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;

            }


        }];

    }

有没有办法避免红色状态栏的出现,或者至少我应该用什么方法让它消失?

【问题讨论】:

  • 跑题了?!来吧,伙计们,你不能是认真的!

标签: ios objective-c uiimagepickercontroller uistatusbar avassetexportsession


【解决方案1】:

事实证明,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;

        }


    }];

}

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-19
    • 2018-10-08
    相关资源
    最近更新 更多