Hi All, it's been a while that I have played around with B4I, I am playing with the PIP Controller, found this code somewhere online and wanted to see if I can get it to work, I am getting an error about the initWithPlayerViewController method not being found
Here's the objective C code
And the rest of the functions are these.
I get the error right at this line in the CreatePIPController function
Any thoughts, It's late for me here and my brain if foggy, I know I must be missing something that I just can't seem to figure out right now.
Thanks,
Walter
Here's the objective C code
PIPController:
#If OBJC
#import <Foundation/Foundation.h>
#import <AVKit/AVKit.h>
#import <AVFoundation/AVFoundation.h>
@end
@interface PIPController: NSObject <AVPictureInPictureControllerDelegate>
@property (nonatomic, strong) AVPictureInPictureController *pipController;
@property (nonatomic, strong) AVPlayerViewController *playerViewController;
- (instancetype)initWithPlayerViewController:(AVPlayerViewController *)playerViewController;
- (void)startPIP;
- (void)stopPIP;
@end
@implementation PIPController
- (instancetype)initWithPlayerViewController:(AVPlayerViewController *)playerViewController {
NSLog(@"inside");
self = [super init];
if (self) {
self.playerViewController = playerViewController;
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:playerViewController.player];
if ([AVPictureInPictureController isPictureInPictureSupported]) {
self.pipController = [[AVPictureInPictureController alloc] initWithPlayerLayer:playerLayer];
self.pipController.delegate = self;
}
}
return self;
}
- (void)startPIP {
if (self.pipController) {
[self.pipController startPictureInPicture];
}
}
- (void)stopPIP {
if (self.pipController) {
[self.pipController stopPictureInPicture];
}
}
#End If
This is how I am Initializing the playerViewController etc.the error I am seeing is the following:
Error occurred on line: 133 (B4XMainPage)
Method not found: initWithPlayerViewController:, target: PIPController
Stack Trace: (
CoreFoundation 42CCFC7B-FF32-3D25-8F01-CCB2AD843A8B + 40516
libobjc.A.dylib objc_exception_throw + 60
CoreFoundation 42CCFC7B-FF32-3D25-8F01-CCB2AD843A8B + 1023016
B4i Example +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 352
B4i Example -[B4INativeObject RunMethod::] + 176
B4i Example -[b4i_b4xmainpage _createpipcontroller::] + 668
B4i Example -[b4i_b4xmainpage _button1_click:] + 512
CoreFoundation 42CCFC7B-FF32-3D25-8F01-CCB2AD843A8B + 476852
CoreFoundation 42CCFC7B-FF32-3D25-8F01-CCB2AD843A8B + 133916
B4i Example +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1348
B4i Example -[B4IShell runMethod:] + 320
B4i Example -[B4IShell raiseEventImpl:method:args::] + 928
B4i Example -[B4IShellBI raiseEvent:eventarams:] + 1008
B4i Example __33-[B4I raiseUIEvent:eventarams:]_block_invoke + 52
libdispatch.dylib DED4D0A5-1420-32AE-83A6-C31D938A1C9A + 9312
libdispatch.dylib DED4D0A5-1420-32AE-83A6-C31D938A1C9A + 16264
libdispatch.dylib DED4D0A5-1420-32AE-83A6-C31D938A1C9A + 75764
libdispatch.dylib _dispatch_main_queue_callback_4CF + 44
CoreFoundation 42CCFC7B-FF32-3D25-8F01-CCB2AD843A8B + 632520
CoreFoundation 42CCFC7B-FF32-3D25-8F01-CCB2AD843A8B + 507948
CoreFoundation CFRunLoopRunSpecific + 612
GraphicsServices GSEventRunModal + 164
UIKitCore CF21AD9C-EFBF-3961-A7C0-54BD30CEFEA9 + 3806824
UIKitCore UIApplicationMain + 340
B4i Example main + 100
dyld 4B042F28-0D14-30EC-A1DE-3DBB10866AD7 + 88416
)
B4X:
playerViewController = CreatePlayerViewController("https://bestvpn.org/html5demos/assets/dizzy.mp4")
VideoPlayer1 = playerViewController.GetField("view")
pip = CreatePIPController(playerViewController)
And the rest of the functions are these.
B4X:
Sub CreatePlayerViewController(videoURL As String) As NativeObject
Dim playerViewController2 As NativeObject
playerViewController2 = playerViewController2.Initialize("AVPlayerViewController").RunMethod("new", Null)
Dim player As NativeObject
player = player.Initialize("AVPlayer").RunMethod("playerWithURL:", Array(CreateURL(videoURL)))
playerViewController2.RunMethod("setPlayer:", Array(player))
Return playerViewController2
End Sub
Sub CreateURL(url As String) As NativeObject
Dim nsurl As NativeObject
nsurl = nsurl.Initialize("NSURL").RunMethod("URLWithString:", Array(url))
''' nsurl.Initialize("NSURL").RunMethod("initWithString:", Array(url))
Dim description As String = nsurl.RunMethod("absoluteString", Null).AsString
Log("nsurl: " & description)
Return nsurl
End Sub
Sub CreatePIPController(playerViewController2 As NativeObject) As NativeObject
Dim pip As NativeObject
pip = pip.Initialize("PIPController").RunMethod("initWithPlayerViewController:", Array(playerViewController2))
Return pip
End Sub
I get the error right at this line in the CreatePIPController function
B4X:
pip = pip.Initialize("PIPController").RunMethod("initWithPlayerViewController:", Array(playerViewController2))
Any thoughts, It's late for me here and my brain if foggy, I know I must be missing something that I just can't seem to figure out right now.
Thanks,
Walter