holzschu / a-shell

A terminal for iOS, with multiple windows
BSD 3-Clause "New" or "Revised" License
2.65k stars 116 forks source link

FR: Directly load Picture-in-Picture (PiP) for "play movie.mp4" #835

Open globalhuman opened 4 days ago

globalhuman commented 4 days ago

I have created some iOS shortcuts to imitate PiP from the stock photos app/gallery app which executes a-shell mini scripts to play a video using the following command:

play movie.mp4

It would be great if there was an option to enable PiP directly from the command such that it opens the video directly in PiP mode i.e.

play movie.mp4 --pip

Is this possible, or are there other methods which would be possible for me to try?

holzschu commented 4 days ago

Hi, I don't see that option in the apple AVPlayer: https://developer.apple.com/documentation/avfoundation/avplayer There's an option to enable PiP, but not one to start the player automatically in PiP, unless I missed something.

holzschu commented 4 days ago

I experimented with a few booleans again, but I couldn't make it run PiP automatically. I think Apple doesn't want PiP to be automatic, it has to require user interaction (clicking on the PiP icon).

There's a neat feature that I haven't advertised, though: if you start playing a video, and you haven't clicked to start PictureInPicture, then a-Shell will continue the sound track (because that's feasible) while removing the video track.

globalhuman commented 3 days ago

I'm not an iOS developer so can only do some basic research on if it's possible. Thanks for experimenting further yourself.

Would the following methods indicate that it could be possible?

https://developer.apple.com/documentation/avkit/avpictureinpicturecontroller/startpictureinpicture()

https://developer.apple.com/documentation/avkit/avpictureinpicturecontroller/canstartpictureinpictureautomaticallyfrominline

globalhuman commented 3 days ago

After reading a little further I realise that the canStartPictureInPictureAutomaticallyFromInline() method indicates that PiP can start automatically when putting the app to the background. I experimented with adding a short wait X seconds then Go to home screen and the video continue playing in the background. So at least as a workaround that seems to help out for now.

Happy for you to close this if your own research finds that it's not possible and that the workaround is sufficient for your users