ios – 在网络视图中播放视频意外结束了背景视频录制?

ios – 在网络视图中播放视频意外结束了背景视频录制?,第1张

概述我正在使用WKWebView在我的应用程序中显示全屏YouTube视频,并使用AVCaptureSession在YouTube上浏览和播放视频时在后台录制音频和视频.按下按钮时捕获会话开始.但是,在录制过程中,当选择YouTube视频并开始全屏播放时,它会立即意外结束录制,因为会调用处理录制结束的委托方法. 请有人向我解释如何解决这个问题?不太确定这是否完全相关,但我收到错误信息,如_BSMach 我正在使用WKWebVIEw在我的应用程序中显示全屏YouTube视频,并使用AVCaptureSession在YouTube上浏览和播放视频时在后台录制音频和视频.按下按钮时捕获会话开始.但是,在录制过程中,当选择YouTube视频并开始全屏播放时,它会立即意外结束录制,因为会调用处理录制结束的委托方法.

请有人向我解释如何解决这个问题?不太确定这是否完全相关,但我收到错误信息,如_BSMachError:(os / kern)无效功能(20)_BSMachError:(os / kern)无效名称(15)和无法同时满足约束.,尽管后者似乎引用了一个单独的autoLayout问题.任何帮助将不胜感激.

此外,我尝试使用UIWebVIEw而不是WKWebVIEw.当我使用UIWebVIEw时,问题是视频录制时YouTube视频甚至无法播放.它将在黑屏上打开并保持在0:00.

这是按下以开始录制的按钮.

- (voID) buttonClickedStart:(UIbutton*)sender //button to start/end recording {    if (!WeAreRecording) {        [self setupVIDeoCapture];         //----- START RECORDING -----        WeAreRecording = YES;        [[AVAudioSession sharedInstance] setcategory:AVAudioSessioncategoryRecord error:nil];        //Create temporary URL to record the vIDeo to for later vIEwing        NSArray *paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES);        Nsstring *basePath = [paths objectAtIndex:0];        Nsstring *outputPath = [[Nsstring alloc] initWithFormat:@"%@",[basePath stringByAppendingPathComponent:@"output.mp4"]];        if ([[NSfileManager defaultManager] isDeletablefileAtPath:outputPath])            [[NSfileManager defaultManager] removeItemAtPath:outputPath error:NulL];        NSURL *outputURL = [[NSURL alloc] initfileURLWithPath:outputPath];        [MovIEfileOutput startRecordingToOutputfileURL:outputURL recordingDelegate:self];        self.outputURLs = outputURL;    }    else {        //----- Stop RECORDING -----        WeAreRecording = NO;        [MovIEfileOutput stopRecording];    }}

这是按下按钮时调用的方法.它设置并启动表示为CaptureSession的捕获会话.

- (voID)setupVIDeoCapture {     // Sets up recording capture session    CaptureSession = [[AVCaptureSession alloc] init];    // Add vIDeo input to capture session    AVCaptureDevice *VIDeoDevice = [AVCaptureDevice     defaultDeviceWithMediaType:AVMediaTypeVIDeo];    if (VIDeoDevice) {        NSError *error;        VIDeoinputDevice = [[AVCaptureDeviceinput alloc] initWithDevice:[self CameraWithposition:AVCaptureDevicepositionFront] error:&error];        if (!error) {            if ([CaptureSession canAddinput:VIDeoinputDevice])                [CaptureSession addinput:VIDeoinputDevice];         }    }    // Add audio input to capture session    AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice   defaultDeviceWithMediaType:AVMediaTypeAudio];    NSError *error = nil;    AVCaptureDeviceinput *audioinput = [AVCaptureDeviceinput  deviceinputWithDevice:audioCaptureDevice error:&error];    if (audioinput) {        [CaptureSession addinput:audioinput];    }    // Add movIE file output to the capture session    MovIEfileOutput = [[AVCaptureMovIEfileOutput alloc] init];    [MovIEfileOutput setMovIEFragmentInterval:kCMTimeInvalID];    if ([CaptureSession canAddOutput:MovIEfileOutput])        [CaptureSession addOutput:MovIEfileOutput];    // Set the output propertIEs (you don't really need to see this code)    [self CameraSetoutputPropertIEs]; // (We call a method as it also has to be done after changing camera)    [CaptureSession setSessionPreset:AVCaptureSessionPresetMedium];    //----- START THE CAPTURE SESSION RUNNING -----    [CaptureSession startRunning];}

这是声明和设置WKWebVIEw的地方.

- (voID)vIEwDIDAppear:(BOol)animated {        [super vIEwDIDAppear:animated];        // Add recording button        CGSize screenSize = [[UIScreen mainScreen] bounds].size;        CGRect rect = CGRectMake(0,screenSize.wIDth,337);        UIbutton *start = [UIbutton buttonWithType:UIbuttonTypeRoundedRect];        [start addTarget:self action:@selector(buttonClickedStart:) forControlEvents:UIControlEventtouchUpInsIDe];        [start setFrame:CGRectMake(30,338,35,35)];        [start setTitle:@"" forState:UIControlStatenormal];        [start setExclusivetouch:YES];        [start setBackgroundImage:[UIImage imagenamed:@"start.png"] forState:UIControlStatenormal];        [self.vIEw addSubvIEw:start];        // Add web vIEw        webVIEw = [[WKWebVIEw alloc] initWithFrame:rect];        [self.vIEw addSubvIEw:webVIEw];        Nsstring *webSite = @"http://www.youtube.com";        NSURL *url = [NSURL URLWithString:webSite];        NSURLRequest *request = [NSURLRequest requestWithURL:url];        webVIEw.navigationDelegate = self;        webVIEw.UIDelegate = self;        [webVIEw loadRequest:request]; // Load up Youtube                   [self.vIEw addSubvIEw:webVIEw];}
解决方法 看起来唯一缺少的是在其他选项中设置混音,在音频会话中播放和录制类别.
[[AVAudioSession sharedInstance] setcategory:AVAudioSessioncategoryPlayAndRecord withOptions:AVAudioSessioncategoryOptionMixWithOthers error:nil];

编辑:设置一个简单的测试,它的工作原理,希望这有帮助!

总结

以上是内存溢出为你收集整理的ios – 在网络视图中播放视频意外结束了背景视频录制?全部内容,希望文章能够帮你解决ios – 在网络视图中播放视频意外结束了背景视频录制?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1107496.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存