MobileMoviePlayer in background

Really appreciate your help here - what I am noticing is that there is no audio on the video clips I have imported into Xojo. There is definitely sound in the on disk video clip.

So the simulator PIP works (even with no audio audible) but the built version does not allow, or show the button to allow, PIP.

Where is the audio going when I import a video?

Mark, did you mean that you dragged the video into the IDE?

Import into project via the File-Import process (which I guess is the same as dragging into the IDE). I then assign the video in the inspector for the MobileMoviePlayer.

Try using a copy file step and assign it in code. I’m wondering if our connection code is mangling your file.

Thanks Greg - that solved the audio missing issue. Something is happening when you import a video file into a project (not sure if just iOS) - these were mp4 files.

Still not getting the PIP option though !

Add this in your App.Opening event:

Declare Function NSClassFromString Lib "Foundation" (clsName As CFStringRef) As ptr
declare function sharedInstance_ lib "AVFoundation" selector "sharedInstance" (clsRef as ptr) as ptr

Dim AVAudioSessionPtr As ptr = sharedInstance_(NSClassFromString("AVAudioSession"))

declare function setCategory_ lib "AVFoundation" selector "setCategory:mode:options:error:" (obj_id as ptr, category as CFStringRef, mode as CFStringRef, options as UInteger, byref outError as ptr) as Boolean
dim err as ptr
Dim category As String = "AVAudioSessionCategoryPlayback"
Dim mode As String = "AVAudioSessionModeMoviePlayback"
Dim options As UInteger = 2
dim result as Boolean = setCategory_(AVAudioSessionPtr, category, mode, options, err)
if err <> nil then
  declare function localizedDescription lib "Foundation" selector "localizedDescription" (obj_id as ptr) as CFStringRef
  Dim errorReason As String =  localizedDescription(err)
  
  Break //Check value of ErrorReason 
elseif result = False then
  Break //something else went wrong
end if

I hope this will activate PiP on your iPad.

3 Likes

YES! Thank you Jeremie. Is this something that should be getting set by the Background-Audio capability in the iOS settings?

So it works?!

No it is completely independent from the background audio entitlement.
This entitlement is to allow your app to play audio/video in the background when your app isn’t facing the user.

The code above tells the system that your app’s purpose is to play video files. Therefore it should stop other audio / video apps playing when you start your app. I believe this is one of the requirements for PiP to work correctly on a real device.

1 Like

Yes it works perfectly. Thank you.

1 Like

So Xojo need to add this entitlement ? Is it worth raising a feedback request?

Code is not the same as an Entitlement. Entitlements are basically a plist file that is embedded in your application at build time as part of the signing process.

Yes but you said this was part of the background-audio capability - my terminology may be mixed up. If this doesn’t function using the Background-Audio capability like you indicated it should then is this a bug?

The checkbox I indicated is a capability/entitlement. The code that Jeremie gave you is not. His code is just for telling the OS how the audio in your app needs to be routed, and it can be changed at runtime. Entitlements cannot.

Sorry - what I am saying is that the XOJO entitlement called Background-Audio does not enable PIP as YOU indicated it did. Is that a bug?

Ah, no. I only indicated it because i happened to have been in there recently and noticed that our dialog didn’t specifically call out video for the one that is named Audio when it should have.

As you indicated here. This does not enable PIP.

Right, but do you also need to have it checked in addition to Jeremie’s code?

Ok, so recently we realized that over time the section of the IDE which was designated for Entitlements also had just standard plist entries in it so we renamed it to be called Capabilities. The Background Mode capability is a standard plist entry (not an Entitlement) which tells the OS that your app needs to run in the background for very specific purposes. I suspect this has to do with power usage in that apps that don’t actually need to run code in the background, simply don’t.

Indeed you do.

Right. It’s working now anyway. Thanks for your help.