Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle app phases (auto pause/play on enter background/active phase) #831

Merged
merged 1 commit into from
Oct 11, 2023

Conversation

sy6sy2
Copy link
Contributor

@sy6sy2 sy6sy2 commented Aug 29, 2023

Hi!

I noticed that when watching a movie on iOS, if I go back to Home Screen without pausing the movie then the movie juste continue playing in background.

This PR adds notification support for active, inactive and background phases of the app and also pause the video when app enter in background and resume the movie when enter in active phase.

This is still a first step, I guess other things can be done about that like stopping instead of pausing for live TV.

@LePips and @jhays if you can have a look on this, I'm a newbie on all the swift and Objective-C stuff...
Thank you!

@sy6sy2 sy6sy2 force-pushed the handle-active-background-phase branch from b82fb39 to f878efa Compare August 30, 2023 19:02
Copy link
Member

@PangMo5 PangMo5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to be able to control this as an option in the settings.
In particular, the part that unpause when you return to the foreground can be an uncomfortable experience for some users.

@sy6sy2
Copy link
Contributor Author

sy6sy2 commented Sep 14, 2023

Yes totally agree with you @PangMo5.
At this state, this PR it's just a POC to show that Jellyfin can handle app phases, but if @LePips is ok with this initial work I will add more commits to this PR before any merge in order to improve the user experience like you suggest.

Some example I think about:

  • For each phase, possibility to set the desired action (e.g. nothing, pause, stop, play, ...).
  • Maybe a different setting for Movies vs Live TV (e.g. on background, pause a movie but stop a live TV).
  • ...

@LePips
Copy link
Member

LePips commented Sep 14, 2023

I agree that this should be customizable, so for now I want 2 new keys under a new section:

// SwiftfinDefaults.swift

extension Defaults.Keys {
	enum VideoPlayer {

	// ...

		enum Transition {
			static let pauseOnBackground // ...
			static let playOnActive // ...
		}
	}
}

This will go in a new Transition section in the Video Player settings, at the bottom as I sort the sections alphabetically in English.

I have already thought about a more comprehensible solution for actions that will completely replace this, but frankly I don't know when I will get to it and will probably need to think about it more. It also may be sooner than expected when I get to it as this is fresh on my mind so 🤷. So, you can either implement these settings for now or wait until I get to it, your choice.

[what I thought of]

Similar to how the video player gestures and action buttons work, there will be a certain set of actions created (play, pause, PiP) that can be selected per active, inactive, and backgrounded. This just lays the foundation for more actions to be easily added and I think is better when it comes to how different media want to react to these transitions. Sounds simple but is a bit more to implement.


Additionally, we have to think about this behavior with the Native player - the main issue being PiP. Since this feature may eventually come to the other player (once I get back to compiling mpv...) it wouldn't hurt to think about this behavior now. Currently, PiP isn't customizable (but should be) and, while I haven't tested it myself, the background pause may conflict with wanting to watch in PiP. Frankly because of this, just leave the Native player alone for now and we can get to it later.

@sy6sy2 sy6sy2 force-pushed the handle-active-background-phase branch 3 times, most recently from baa4185 to 869ce2e Compare October 7, 2023 13:22
@sy6sy2 sy6sy2 force-pushed the handle-active-background-phase branch from 869ce2e to 8b1b9af Compare October 10, 2023 18:08
@LePips LePips merged commit 667d48b into jellyfin:main Oct 11, 2023
@LePips LePips added the enhancement New feature or request label Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants