iOS 14 AVPlayer not showing video, but playing sound - objective-c

Old Objective C project that plays video and works perfectly on iOS 13 and below (and iOS 14.2 beta), but on iOS 14.0 it only plays sound from the video. The video is blank.
Any idea why this is?
I load the video like this:
_videoPlayer = [AVPlayer playerWithURL:url];
playerLayer = [AVPlayerLayer playerLayerWithPlayer:_videoPlayer];
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
playerLayer.needsDisplayOnBoundsChange = YES;
_videoPlayer.actionAtItemEnd = AVPlayerActionAtItemEndPause;
playerLayer.frame = _videoContainer.bounds;
[_videoContainer.layer addSublayer:playerLayer];
[_videoContainer bringSubviewToFront:_playButton];
[_videoPlayer addObserver:self forKeyPath:#"rate" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:nil];
_videoContainer is just a standard UIView.

Related

Objective C iOS WKWebView Background

Hopefully someone can help.
I've got an application that currently uses the UIWebview to play audio, which works even if the device is locked as I enable mediaPlaybackAllowsAirPlay.
However I started to move the code to use the new WKWebView and I've enabled mediaPlaybackAllowsAirPlay, However when I press the lock button, the WebView stops playing the audio.
Any ideas how I can get WKWebview to behave like the UIWebView?
Update, Here's an example of my code:
WKUserContentController *wkUController = [[WKUserContentController alloc] init];
WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
theConfiguration.userContentController = wkUController;
theConfiguration.allowsAirPlayForMediaPlayback = YES;
webViewActive = [[WKWebView alloc] initWithFrame:viewForWeb.frame configuration:theConfiguration];
webViewActive.navigationDelegate = self;
webViewActive.frame = viewForWeb.bounds;
[webViewActive setAutoresizingMask: UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
[viewForWeb addSubview:webViewActive];
NSURL *nsurl=[NSURL URLWithString:#"URL TO AUDIO"];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webViewActive loadRequest:nsrequest];
Thanks

How to add QLPreviewController as Subview in objective C - iOS8

In previous iOS versions I used to add the QLPreviewController as a subview. It is very handy to use my own app headers and navigation bar but in iOS 8 it adds a white space just below the header. It is the space for its own navigator bar.
You can see the attached img:
I use this code:
QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.dataSource = self;
previewController.delegate = self;
previewController.currentPreviewItemIndex = 0;
previewController.view.frame = CGRectMake(0, 0, self.containerView.frame.size.width, self.containerView.frame.size.height);
[self addChildViewController:previewController];
[previewController didMoveToParentViewController:self];
[self.containerView addSubview:previewController.view];
How can i mantain the iOS7 funcionality? I only want to hide the qlpreviewcontroller navigationbar
Thanks
I'm solving the EXACT same problem. The only solution I found so far is the following:
// qlController.view.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));//self.view.bounds;
// qlController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self addChildViewController:qlController];
[self.view addSubview:qlController.view];
NSDictionary *bindings = #{#"qlPreviewController": qlController.view};
qlController.view.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|[qlPreviewController]|" options:0 metrics:nil views:bindings]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:|[qlPreviewController]|" options:0 metrics:nil views:bindings]];
[qlController didMoveToParentViewController:self];
Commented lines are legacy code, that worked perfectly on iOs7. The main idea is stop using spring and struts and start using auto layout. Results looks good enough, but still there are some problems with rotations.
Works good:
Iphone 4s/5/6/6+ iOs7 portrait + landscape, iOs8 portrait
IPad all models iOs7,8 portrait + landscape
Works bad:
Iphone 4s/5/6/6+ iOs8 landscape : has some spacing between navBar and content. I think it is problem with Apple's QLPreviewController rather than my code.

how to switch camera mode to video mode using GPUImage in ios

I am making app like Instagram .i am using GPUImage framework ,in this i have to take photos and videos and share. i able to capture photos using this framework and now i have to capture video but i am struggling how to change camera mode photos to video. any help and tutorial then its very good for me. I used this code camera for photos mode.
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
self.imagepicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[[NSBundle mainBundle] loadNibNamed:#"OverlayView" owner:self options:nil];
self.overlayView.frame = self.imagepicker.cameraOverlayView.frame;
self.imagepicker.cameraOverlayView = self.overlayView;
self.overlayView = nil;
CGSize result = [[UIScreen mainScreen] bounds].size;
self.imagepicker.showsCameraControls = NO;
self.imagepicker.allowsEditing = NO;
self.imagepicker.wantsFullScreenLayout = NO;
// self.imagepicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
}
else{
self.imagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
In my case, I'm using GPUImage to do both (pictures and videos). Therefore I've created two objects: one of type GPUImageStillCamera(pictures) and other of type GPUImageVideoCamera (videos).
So whenever you need to switch between cameras you basically stop the GPUImageStillCamera capture and initialize a video camera (note that you have to adapt this snippet to your project):
func initializeVideoCamera() {
// Stop the capture of GPUImageStillCamera
stillCamera.stopCameraCapture()
videoCamera = GPUImageVideoCamera.init(sessionPreset: AVCaptureSessionPreset1920x1080, cameraPosition: .Back)
videoCamera?.outputImageOrientation = .Portrait
videoCamera?.addTarget(filter)
// If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie
unlink(pathToMovieFile)
initializeWriteWithPath(pathToMovieFile)
videoCamera?.startCameraCapture()
}

Xcode 4.5 Black Screen or Exception: 'A view can only be associated with at most one view controller at a time!'

I have an existing iPhone app that was working fine in Xcode 4.0 prior to upgrading to Xcode 4.5. Upon upgrading, now I get a Black Screen when running in the iPhone/iPad 4.3 Simulator and get the following Exception when running the iPhone/iPad 6.0 Simulator.
Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View <CCGLView: 0x8c7f380; frame = (0 0; 320 480); layer = <CAEAGLLayer: 0x8c7f670>> is associated with <CCDirectorDisplayLink = 0x994c7f0 | Size: 320 x 480, view = <CCGLView: 0x8c7f380; frame = (0 0; 320 480); layer = <CAEAGLLayer: 0x8c7f670>>>. Clear this association before associating this view with <RootViewController: 0x8c7ef00>.'
The app is using Cocos2D 2.0, and is pretty simple based on a tutorial found online. There is no XIB file. Everything is being done programmatically.
These are the lines that cause the exception in the 6.0 Simulator (from IOS6TestAppDelegate.m):
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
[enter link description here][1]viewController.wantsFullScreenLayout = YES;
If these lines are commented out, then the 6.0 Simulator shows a black screen as well, instead of the regular menu screen.
I've searched online for solutions on this and tried a number of things, but have been unable to make progress. I'm fairly new to iPhone programming (though am not new to programming in general) and am really struggling with this. I would really appreciate any help.
First, delete
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;
Then replace
[window setRootViewController:viewController];
With
if( ! [director enableRetinaDisplay:YES] )
CCLOG(#"Retina Display Not supported");
// Create a Navigation Controller with the Director
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:director];
navController.navigationBarHidden = YES;
NSString *reqSysVer = #"6.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
{
[window setRootViewController:navController];
} else
{
[window addSubview: navController.view];
}
That should do it!

Gamecenter Matchmaking Doesn't Work

Here is my Menu.m's onEnter method:
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = 2;
request.maxPlayers = 2;
GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
mmvc.matchmakerDelegate = self;
tempVC = [[UIViewController alloc] init];
[[[CCDirector sharedDirector] view] addSubview:tempVC.view];
[tempVC presentModalViewController: mmvc animated: NO];
mmvc.view.frame = CGRectMake(150, 150, 510, 420);
I tried with device and simulator but they couldn't match.
I also tried it to do by following Ray Wenderlich's tutorial:
But then, even matchmakerviewcontroller didn't show up. I don't know what I'm doing wrong.
Thanks in advance.
Are you using two different game center IDs -- one for your simulator and one for your device?
Is your device logged into the game center sandbox?
The simulator will use the game center sandbox, and your device must also use the sandbox for the two to connect.
You can log into the game center sandbox by logging out of the game center, and then starting your app. Your app should ask you to log into game center. Performing the login through your non-released app will put you in the game center sandbox.