shaka-project / shaka-player-embedded

Shaka Player in a C++ Framework
Apache License 2.0
239 stars 62 forks source link

Expose text cues to Objective-C/Swift #171

Open kareljuricka opened 3 years ago

kareljuricka commented 3 years ago

It's possible to somehow access Shaka Player Embedded JSContext? I would like to register some custom swift methods, which I'd like to call from my custom JS code inside shaka-player js library. Thanks for your answer.

TheModMaker commented 3 years ago

What are you trying to do? The top-level API tries to remove the JavaScript interactions and treat it like it is a native API. So if you are trying to get some event or callback, it would be better to just expose those as native functions on the client objects instead of exposing internals like that.

kareljuricka commented 3 years ago

We are using own TextDisplayer for subtitles. In classic shaka player, we using DOM methods to generate custom subtitles to screen - accessing DOM elements with custom css styles. For shaka player embedded this solution doesn't work - it hasn't got mapped all necessary DOM methods, elements, css styles, etc..

So our idea was access some swift methods to do same work using some custom UIView. Those methods we wanted to call directly from our shaka-player JS, so it wouldn't be necessary to changing Shaka-player-embedded source codes.

I found that's is possible to call swift methods from JS, but they has to be registered to JSContext. And if I create this context inside my swift code, it's logically different from JS context of shaka-player-embedded.

Practically, we only need to send some String from our JS code, receive them in our swift app and react on them real time.

it would be better to just expose those as native functions on the client objects instead of exposing internals like that. - if this is is still right approach for our problem, can you please give me little more advice? Does it mean that I have to change shaka-player-embedded and do some changes in C or Objective-C code?

TheModMaker commented 3 years ago

We have an C++ API to do that (and we expect C++ apps to do this themselves). You could switch to using the C++ objects directly, and then you can see the text objects to render them yourselves. You can see the C++ demo to see how to use the C++ objects.

We could expose this info to allow Objective-C/Swift apps to handle the text rendering too.