Just experimenting with the new MobileMoviePlayer control and getting it working etc is extremely simple and works well. What it doesn’t do is carry on playing in the Picture in Picture mode like other video applications. Is this possible using Xojo - do I need declares to make this work or is there a specific entitlement I need to enable?
Any help appreciated.
What is odd Is when I run the project in Xojo and view it on the simulator the PIP option is shown and works fine. When I build and copy to the device (iPad Pro 12.9) the PIP option is not shown?
In the simulator I see this:
In the built app I only see the expand arrows to the left of this button.
It’s unclear to me what Apple class that Xojo is using, but if it’s an AVPlayerViewController you should be able to do this (untested):
Declare sub setAllowsPiP Lin “AVFoundation.framework” selector “setAllowsPictureInPicturePlayback:” (Obj as ptr, yesNo as Boolean)
The other thing you will need to do is set the entitlement. Currently you can get to this by going to the iOS build target and on the inspector, click to the Advanced tab. In the list that’s there, turn on Background Modes and then click Options. You’ll need to select Audio (actually it’s Audio, Airplay and Picture in Picture).
@Greg_O_Lone can you comment on what the underlying class is for the MobileMoviePlayer?
Yeah I did check that on the off chance. I’ll take another look shortly. thanks.
Thanks Jason - I get an error ‘ cannot find a type or module with this name’ “AVFoundation.framework”
Try this one:
Declare sub setAllowsPiP Lib "AVFoundation.framework" selector "setAllowsPictureInPicturePlayback:" (Obj as ptr, yesNo as Boolean)
BTW, you don’t need the “.framework” part for built in stuff
Same error. It’s probably something I’m doing wrong.
Thanks - still get the same error but without the .framework element now.
I can’t seem to find what is the underlying class of MobileMoviePlayer…
Using simple declares to get the class name and also using Reveal give AVPlayerView which is not a standard AVFoundation class on iOS.
All attempts of declaring into MobileMoviePlayer resulted in a crash.
Taking a quick look at the code, it looks like Handle is returning the View that is wrapped around the AVPlayer.
Please file a bug report about that.
FWIW you can also use a declare to find out what the underlying class of a handle is on macOS and iOS:
Declare Function getClassName Lib "Foundation" selector "className" (obj As ptr) As CFstringref
Var className as String = getClassName(item.Handle)
This code also reveals that it’s an AVPlayerView
My guess is that the simulator uses AVPlayerView and the device uses AVPlayerViewController as they’re darn near identical and you are expected to just not call the macOS-only selectors.
That said, while I’m not getting errors, I am getting crashes for unknown selectors.
I’m trying to do this:
Declare Function player Lib "AVKit" selector "player" (obj As ptr) As ptr
Who should file this sorry - I don’t understand enough about the issue to be able to log a comprehensive bug report but can log a basic call referencing this discussion?
Actually I don’t think there is a bug here.
I was able to get access to the AVPlayerViewController like this:
Declare Function NSClassFromString Lib "Foundation" (clsName As CFStringRef) As ptr
Declare Function isKindOfClass Lib "UIKit" selector "isKindOfClass:" (obj_id As ptr, cls As ptr) As Boolean
Declare function nextResponder lib "UIKit" selector "nextResponder" (obj as ptr) as ptr
Var AVPlayerViewController as ptr = nextResponder(MoviePlayer1.Handle)
if isKindOfClass(AVPlayerViewController, NSClassFromString("AVPlayerViewController")) then
Declare sub setAllowsPiP Lib "AVKit" selector "setAllowsPictureInPicturePlayback:" (Obj as ptr, yesNo as Boolean)
It seems that the default value of AllowsPictureInPicturePlayback is always True, on devices that support PiP.
Back to square one, I believe picture in picture will work when the Audio background mode entitlement is set to True.
Well it doesn’t when I run my app on my IPad Pro 12.9
There is one more thing to check, setting the audio session type.
I will post the necessary code later today when I get back to my Mac.