Getting error when trying to use AVPictureInPictureController in iOS 13 or tvOS 13
Asked Answered
I

3

11

I have small app which runs on iOS and tvOS where I’m displaying a video in UIView.It does support iOS 12 and tvOS 12. Now want to show PIP for tvOS hence trying to use AVPictureInPictureController gives error “Use of undeclared identifier 'AVPictureInPictureController”.

Even though deployment target set to tvOS 13. In Xcode, capabilities -> Background mode -> enabled “ Audio,Airplay and Picture In Picture”. This basic code gives error.

#import <AVKit/AVKit.h>
if ([AVPictureInPictureController isPictureInPictureSupported]) {
   // code 
}

Any other settings missing or something else I need do ?

Thanks

Ilarrold answered 30/10, 2019 at 7:5 Comment(0)
C
0

Not supported in tvOS, as stated in Apple's documentation

SDKs

iOS 9.0+

macOS 10.15+

Mac Catalyst 13.0+

Carbolated answered 14/11, 2019 at 10:13 Comment(5)
tried importing AVFoundation also.. still same error.Ilarrold
- yes.. just now tried it.. still same error. I think "AVPictureInPictureController" is not supported on tvOS13 (not sure).Ilarrold
No, it's not, check my updated answer. Sorry, I thought that it gives the error on iOSCarbolated
as per this link - developer.apple.com/documentation/avkit/… - looks it may possible to implement it( again not sure)Ilarrold
Initially Make Sure that you set Playback audio category, Generally on use of AVPlayerViewController to play video content. PIP mode will automatically get invoked if the developed application enters background , but only if satisfies the montioned condition. The Player which we are using should be in Full Screen Mode,The Video Should be Playing in it and PIP Should be supported by the device and finally write delegate method to restore our player UI when the user returns from PIP mode. The Video Should be Playing in it and PIP Should be supported by the device. source : shorturl.at/AEXY8Passivism
P
-2

POSSIBLITY OF ISSUES DUE TO THE GAPS IN IMPLEMENTATION :

Experince with the AVPlayerViewController: Initially make Sure that we set Playback audio category, Generally when we use a AVPlayerViewController to play video content. PIP mode will automatically get invoked if the developed application enters background , but only if satisfies the below mentioned condition,First one is the Player which we are using should be in Full Screen mode,the second is we should make sure that the Video Should be Playing in it and third one is PIP Should be supported by the device and last of all write delegate method to restore our player UI when the user returns from Picture in Picture mode.

Implmentation with _AVPictureInPictureController : You can find an working example in the below thread. How to display AVPictureInPictureController?

Drilling down the issue: In order to confirm the undeclared error was not due to the gaps in implementation and it was due to environmnet in Xcode, Download the source and then add the Sources folder inside another folder in your workspace.Add the folder using "Add Files to ..." option and now verify inside xcode.

POSSIBLITY OF ISSUE DUE TO REFRESH IN THE XCODE Try Fix By Approach 1 Include the class explicitly in header and/or body - instead of the *.pch file. Then this error might go away. Also deleting the derived data workes once in a while. Did you change the location in preferences recently by any chance. Some get this error when they use a ramdisk for derived data and then they go back to default. This is the most annoying case - since it causes this error to appear then in almost every file.

Try Fix By Approach 2 Sometime a simple solution might help delete one of the #import lines from the pch file and recompile which will fail as expected.Then put the deleted line back in, recompiled and it compiled normally with all the false errors gone.

POSSIBLITY OF ISSUE DUR TO XCODE ERROR CACHE, FOLLOW THE BELOW STEPS Clean Build : Command-Option-Shift-K to clean out the build folder. Reset Simulator : choose iOS Simulator > Reset Content and Settings Restart Xcode Delete your DerivedData folder in ~/Library/Developer/Xcode/DerivedData Restart Computer

Delete the /var/folders in a very targetted way. rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"

Source: How to Empty Caches and Clean All Targets Xcode 4 and later Xcode "Use of undeclared identifier" errors, compiles/runs just fine Use of undeclared identifier in Xcode 9.0 https://developer.apple.com/documentation/avkit/adopting_picture_in_picture_in_a_standard_player

Passivism answered 21/11, 2019 at 11:15 Comment(0)
U
-2

To create a simple video player

First, you'll need to implement a basic video player in your project's ViewController.m file, like so:

#import "ViewController.h"

#import <AVKit/AVKit.h>

@interface ViewController ()
@property(nonatomic) AVPlayerViewController *playerViewController;
@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  self.view.backgroundColor = [UIColor blackColor];

  // Create a stream video player.
  AVPlayer *player = [[AVPlayer alloc] init];
  self.playerViewController = [[AVPlayerViewController alloc] init];
  self.playerViewController.player = player;

  // Attach video player to view hierarchy.
  [self addChildViewController:self.playerViewController];
  self.playerViewController.view.frame = self.view.bounds;
  [self.view addSubview:self.playerViewController.view];
  [self.playerViewController didMoveToParentViewController:self];
}

@end

For further help go through https://help.apple.com/xcode/mac/8.0/#/dev51a648b07

Uniseptate answered 21/11, 2019 at 13:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.