TVML resumable player (in tvOS 14)

177 views Asked by At

I have a TVML/TVJS app that presents a document with a number of playable items. Each item is a lockup element with an event handler to launch the built-in media player, very much like in the example project:

https://developer.apple.com/documentation/tvmljs/playing_media_in_a_client-server_app

In the example code, the event handler creates a new Player object from scratch every time it is triggered, but I would like the player to be resumable: when the user exits the player (e.g. with the menu button) and returns by selecting the item again, I would like to resume the player where it left off.

Before, I would do this by creating Player objects for each item already when the document is loaded (including Playlist and MediaItem), and just execute player.select() or player.play() in the event handler. That would work well.

Since tvOS 14, creating all these Player objects when the document loads seems to overload the app (perhaps it already starts fetching all these items from the network). So I no longer create the Player objects beforehand, but I check in the event handler if I already have a Player for the item, and I create it when it's the first time, otherwise I reuse the Player object.

But even though I checked that I reuse the existing Player object, calling play() or present() causes the playback to restart from the beginning. So what would be the appropriate way to obtain a resumable player?

0

There are 0 answers