iOS Question PIP video Play in Release Mode

walterf25

Expert
Licensed User
Longtime User
Hi All, I recently shared this project that allows you to play a video in PIP (Picture in Picture) Mode, what I didn't realize is that it only works when running in debug mode, I recently tried building a release build and to my surprise the video doesn't continue playing after the home button is pressed.

https://www.b4x.com/android/forum/threads/pip-video-controller.162375/

I was hoping someone could help me figure out why that is?

Regards,
Walter
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

walterf25

Expert
Licensed User
Longtime User
In debug mode, the debugger adds a request to keep the process running for a few more minutes. You can also do it with this code: https://www.b4x.com/android/forum/threads/lack-of-services-in-ios.130536/post-821810

However this is not the correct solution for background playback.

You need something like: https://www.b4x.com/android/forum/threads/background-playback.49337/#content
So I already have a configureAudioSession Objective C code added, that is what allows the video to play in PIP mode, and I can see the small window stays floating on the screen playing the video, but this only happens in debug mode and not in release mode.
audioSessionHelper:
@end
@interface AudioSessionHelper : NSObject
+ (void)configureAudioSession;
+ (void)register;
+ (MPRemoteCommandHandlerStatus)play;
+ (MPRemoteCommandHandlerStatus)pause;
@end

@implementation AudioSessionHelper

+ (void)configureAudioSession {
    NSError *error = nil;
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
                                     withOptions:AVAudioSessionCategoryOptionMixWithOthers
                                           error:&error];
    if (error) {
        NSLog(@"Error setting audio session category: %@", error);
    } else {
        [[AVAudioSession sharedInstance] setActive:YES error:&error];
        [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
        if (error) {
            NSLog(@"Error activating audio session: %@", error);
        }
    }
}

+ (void)register {
   MPRemoteCommandCenter* center = [MPRemoteCommandCenter sharedCommandCenter];
   NSLog(@"registering...");
   center.playCommand.enabled = true;
   center.pauseCommand.enabled = true;
   [center.playCommand addTarget:self action:@selector(play)];
   [center.pauseCommand addTarget:self action:@selector(pause)];
}

+ (MPRemoteCommandHandlerStatus) play {
   NSLog(@"test");
   [B4IObjectWrapper raiseEvent:self :@"controlevent:"  :@[@"play"]];
   return MPRemoteCommandHandlerStatusSuccess;

}

+ (MPRemoteCommandHandlerStatus) pause {
   [B4IObjectWrapper raiseEvent:self :@"controlevent:"  :@[@"pause"]];
   return MPRemoteCommandHandlerStatusSuccess;
}

1722894644813.png


Any other suggestions?

Walter
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Not sure if this will help, but I have checked everything in my project and I can't see what can be different between running in debug mode and release mode, I did however looked at the Info.plist files between the debug run and release run, I'm not sure I know how to read these two files correctly, but by doing a comparison using a Notepad++ plug in, I can see there are some differences.
This is the content of the Info.plist from the release run

bplist00ß"

!"#$%%&'.23%456795=>?@>ABCDEFJMNDQUW_BuildMachineOSBuild_CFBundleDevelopmentRegion_CFBundleDisplayName_CFBundleExecutable_CFBundleIconName]CFBundleIcons_CFBundleIcons~ipad_CFBundleIdentifier_CFBundleInfoDictionaryVersion\CFBundleName_CFBundlePackageType_CFBundleShortVersionString_CFBundleSignature_CFBundleSupportedPlatforms_CFBundleURLTypes_CFBundleVersionZDTCompiler_DTPlatformBuild^DTPlatformName_DTPlatformVersionZDTSDKBuildYDTSDKNameWDTXcode\DTXcodeBuild_LSRequiresIPhoneOS_MinimumOSVersion_UIBackgroundModes^UIDeviceFamily_UILaunchStoryboardName_UIRequiredDeviceCapabilities_UIRequiresFullScreen_ UISupportedInterfaceOrientations_%UISupportedInterfaceOrientations~ipad_UIUserInterfaceStyleU23C71RenXPIP TestWAppIconÑ()_CFBundlePrimaryIconÒ*+,&_CFBundleIconFiles_CFBundleIconName¡-\AppIcon60x60Ñ(/Ò*+0&¢-1\AppIcon76x76_genesis.pip.testS6.0TAPPLU1.0.0T????¡8XiPhoneOS¡:Ñ;<_CFBundleURLSchemes¡2_"com.apple.compilers.llvm.clang.1_0V21E210XiphoneosT17.4\iphoneos17.4T1530W15E204a T14.0£GHIUaudioWairplay_picture-in-picture¢KL\LaunchScreen¡OUarm64 £RST_UIInterfaceOrientationPortrait_#UIInterfaceOrientationLandscapeLeft_$UIInterfaceOrientationLandscapeRight¤RSTV_(UIInterfaceOrientationPortraitUpsideDownULight O e — ¬ ¿ Í â ÷$:Wkˆ›¸ÊÙíø
,?Sb{š±Ôü%-0FK_rt„‰Œ™¬°µ»ÀÂËÍÐåç!.3;<AEKShkmo|~„…‰ªÐ÷ü' X -

And this is the Info.plist file content from the debug run.
bplist00ß"

!"#$%%&'.23%456795>?@A?BCDEFGKNOERVX_BuildMachineOSBuild_CFBundleDevelopmentRegion_CFBundleDisplayName_CFBundleExecutable_CFBundleIconName]CFBundleIcons_CFBundleIcons~ipad_CFBundleIdentifier_CFBundleInfoDictionaryVersion\CFBundleName_CFBundlePackageType_CFBundleShortVersionString_CFBundleSignature_CFBundleSupportedPlatforms_CFBundleURLTypes_CFBundleVersionZDTCompiler_DTPlatformBuild^DTPlatformName_DTPlatformVersionZDTSDKBuildYDTSDKNameWDTXcode\DTXcodeBuild_LSRequiresIPhoneOS_MinimumOSVersion_UIBackgroundModes^UIDeviceFamily_UILaunchStoryboardName_UIRequiredDeviceCapabilities_UIRequiresFullScreen_ UISupportedInterfaceOrientations_%UISupportedInterfaceOrientations~ipad_UIUserInterfaceStyleU23C71RenXPIP TestWAppIconÑ()_CFBundlePrimaryIconÒ*+,&_CFBundleIconFiles_CFBundleIconName¡-\AppIcon60x60Ñ(/Ò*+0&¢-1\AppIcon76x76_genesis.pip.testS6.0TAPPLU1.0.0T????¡8XiPhoneOS¡:Ñ;<_CFBundleURLSchemes¡=Zb4idebug31_"com.apple.compilers.llvm.clang.1_0V21E210XiphoneosT17.4\iphoneos17.4T1530W15E204a T14.0£HIJUaudioWairplay_picture-in-picture¢LM\LaunchScreen¡PUarm64 £STU_UIInterfaceOrientationPortrait_#UIInterfaceOrientationLandscapeLeft_$UIInterfaceOrientationLandscapeRight¤STUW_(UIInterfaceOrientationPortraitUpsideDownULight O e — ¬ ¿ Í â ÷$:Wkˆ›¸ÊÙíø
,?Sb{š±Ôü%-0FK_rt„‰Œ™¬°µ»ÀÂËÍÐåçò',9>FGLPV^svxz‡‰”µÛ2 Y 8

Regards,
Walter
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Please upload a small example with only this feature and I'll test it.
Here's the example project

To reproduce the issue, run the project in debug mode, Press on the Play button for the video to start playing, then exit the app by pressing the home button and you should see the video continue playing in a small window in PIP mode.

Then compile the app in Release mode and repeat the steps above, when you press on the home button you will not see the video continues playing in PIP mode.

Thanks,
Walter
 

Attachments

  • PIP_Test.zip
    169.8 KB · Views: 29
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It looks like you need to change to PIP mode before the application is going into the background.

Example:
B4X:
Sub StartPlayingVideo(playerViewController2 As NativeObject)
    Dim player As NativeObject = playerViewController2.GetField("player")
    player.RunMethod("play", Null)
    StartPIP
End Sub

I tried to call it from B4XPage_Disappear and it didn't work.
Might work from Application_Inactive.

And worth adding a call to StartBackgroundTask (put the inline OBJC before the current ones).
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
It looks like you need to change to PIP mode before the application is going into the background.

Example:
B4X:
Sub StartPlayingVideo(playerViewController2 As NativeObject)
    Dim player As NativeObject = playerViewController2.GetField("player")
    player.RunMethod("play", Null)
    StartPIP
End Sub

I tried to call it from B4XPage_Disappear and it didn't work.
Might work from Application_Inactive.

And worth adding a call to StartBackgroundTask (put the inline OBJC before the current ones).
I tried that and it works sometimes and sometimes it doesn't, very frustrating.

Walter
 
Upvote 0
Top