SRGSSR / srgmediaplayer-apple

An advanced media player library, simple and reliable
MIT License
159 stars 33 forks source link

Subtitle restoration #58

Closed defagos closed 5 years ago

defagos commented 5 years ago

The previous subtitle setting should be restored (if possible) when playing a media. This seems to work somehow with AVPlayerController (which then changes the subtitles loaded by SRG Media Player). Something must therefore be missing in SRG Media Player implementation.

Issue type

Incorrect behavior

Description of the problem

Reproducibility

Always reproducible

Steps to reproduce

  1. Open the demo.
  2. Play the advanced Apple stream with the iOS standard player. Choose French subtitles. Reopen the same player and the same stream. Subtitles are already selected.
  3. Open the same stream with SRG Media Player. The French subtitles are displayed.
  4. Select the Japanese ones. Reopen the media with SRG Media Player. Subtitles start in French, which means something was not set properly.

Note that audio tracks are not restored (repeat the same steps with iOS standard player, but changing audio tracks).

defagos commented 5 years ago

This behavior crosses app boundaries. Playing http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8 in Safari will restore the previous subtitle track as well.

defagos commented 5 years ago

This behavior is probably related to MediaAccessibility, described at WWDC. AVPlayerViewController namely only displays SDH choices (unlike our tracks controller which displays everything), and an Automatic choice probably based on the preferred language order.

We should probably improve our track selection popup to closely match standard behavior.

defagos commented 5 years ago

Yep, this is related to MediaAccessibility. After having changed languages in AVPlayerViewController, MACaptionAppearanceCopySelectedLanguages returns the newly set language. We must probably do the same and call MACaptionAppearanceAddSelectedLanguage.

defagos commented 5 years ago

There was far more than restoration. I also improved the way subtitles can be enabled, using MediaAccessibility settings:

This mimics AVPlayerViewController behavior. For this reason, no audio restoration is performed at all.

To improve the user experience, we also now display for each track option:

AVPlayerViewController only use the display name, but having both is better (most notably if the friendly title contains more information or is localized). This behavior is similar to the user experience when changing the device language (new language as title, translation in the current language as subtitle).

Moreover, the tracks popover now stays visible after having selected an option. This makes it possible to change audio and subtitle tracks at the same time, without having to reopen the popover. I also added two new delegate methods, so that custom player layouts can be informed when the popover is being displayed or hidden. SRGMediaPlayerViewController is now using these delegate methods to prevent its user interface from being hidden while the popover is displayed.