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

Add playback HUD support #893

Merged
merged 27 commits into from
May 24, 2024
Merged

Add playback HUD support #893

merged 27 commits into from
May 24, 2024

Conversation

defagos
Copy link
Member

@defagos defagos commented May 24, 2024

Description

This PR extends playback HUD support officially available for tvOS to iOS.

Technical considerations

The playback HUD overlay, which can be enabled from the tvOS developer settings, is displayed using a private text layer class AVNetworkPlaybackPerfHUDLayer. After inspection with Hopper it appears that the appearance of this overlay is governed by a preference com.apple.avfoundation.videoperformancehud.plist that can be manipulated with:

UserDefaults(suiteName: "com.apple.avfoundation.videoperformancehud")

With closer inspection of -[AVNetworkPlaybackPerfHUDLayer getHudSetting] in Hopper we can find that the following parameters are supported:

  • enable: Manages overlay visibility.
  • color: The text color (an integer) with yellow = 0, green = 1, red = 2, blue = 3 and white otherwise.
  • xoffset: The x-offset for the text.
  • yoffset: The y-offset for the text.
  • fontsize: The size of the font.
  • interval: The refresh interval.

There are also spatial, opacity and show_complete_uri parameters but these seem not to have significant use for us.

The AVNetworkPlaybackPerfHUDLayer class is available for iOS as well but has no visible setting. We can display it by tweaking the com.apple.avfoundation.videoperformancehud user defaults but:

  • The font size logic is quite awkward. The default size if omitted works well on all devices and simulators (though in some cases it might be too big) but some magic is applied in -[AVNetworkPlaybackPerfHUDLayer updateHudWithDisplayString:] which, if a fixed value is set (> 8), leads to various results on iOS / tvOS, also not consistent between simulator and device (on device the device scale is somehow omitted).
  • The defaults are reset between application launches on device (they are preserved in the simulator, though). On tvOS the default system developer setting provides the default behavior obtained after launch.

We can thus deliver in-app playback HUD settings with a few limitations:

  • Parameters will be reset between app launches on device. On tvOS the initial visibility matches the corresponding option from the developer system settings.
  • Fonts need to be adjusted for a good result on each platform.
tvOS iOS
tvOS iOS

For these reasons, and since we are accessing a private preference property list, the feature should not be provided by the framework but only in the demo. People interested in testing their streams with Pillarbox can still enable the feature and copy / paste their stream URL in the demo for closer inspection.

Changes made

The PR adds demo settings for the playback HUD. This makes the playback HUD accessible on iOS as well and provides additional customization possibilities on tvOS:

  • Visibility (on / off).
  • Font size, which 3 sizes (small, default, large) tailored per device.
  • Font color.
  • X and Y offsets (quite useful on iOS where safe area insets can get in the way).

Other parameters are less relevant and are not supported. A reset button is also provided to return to default settings (still reset anyway with the next app cold start).

A few other improvements have been made:

  • Remove focusable modifier on a footer (not really useful for navigation purposes at the moment).
  • Fix simple player view appearance.

Checklist

  • APIs have been properly documented (if relevant).
  • The documentation has been updated (if relevant).
  • New unit tests have been written (if relevant).
  • The demo has been updated (if relevant).

@defagos defagos self-assigned this May 24, 2024
@defagos defagos added the enhancement New feature or request label May 24, 2024
@defagos defagos enabled auto-merge May 24, 2024 12:17
Demo/Sources/Model/PlaybackHudColor.swift Outdated Show resolved Hide resolved
Demo/Sources/Settings/SettingsView.swift Outdated Show resolved Hide resolved
Demo/Resources/Localizable.xcstrings Show resolved Hide resolved
@waliid
Copy link
Member

waliid commented May 24, 2024

On the Mac app (designed for iPad) we have the following log which can be considered as a log noise.

Couldn't write values for keys (
    enable
) in CFPrefsPlistSource<0x600001923cc0> (Domain: com.apple.avfoundation.videoperformancehud, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: No): setting preferences outside an application's container requires user-preference-write or file-write-data sandbox access

@defagos defagos added this pull request to the merge queue May 24, 2024
Merged via the queue into main with commit 1e5c971 May 24, 2024
6 checks passed
@defagos defagos deleted the playback-hud branch May 24, 2024 14:48
@defagos
Copy link
Member Author

defagos commented May 27, 2024

We could submit official Playback HUD support for iOS to Apple but let us wait a bit and see what happens at WWDC.

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
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants