silvermine / videojs-chromecast

MIT License
148 stars 75 forks source link

[Help needed] How to define different sources for chromecast than for the normal player #101

Closed leomelki closed 3 years ago

leomelki commented 3 years ago

Hello, i've been searching on this repo for some time but I still can't figure out how to set custom urls for chromecast. I'm using a custom HLS method that can't work on chromecast so I want to define a normal mp4 url for the chromecast service to use when needed, instead of just not working.

Is it possible, and if so, how can I achieve this please ?

Thanks a lot !

dwassing commented 3 years ago

Hello @leomelki,

I am not certain what the best course of action here is, but I can tell you this much:

In ChromecastTech.js, the sources are gathered from the videoJS player ( see line 91, this._playSource({ src: this.videojsPlayer.src() }, 0);, which in turn is fed into the Chrome Cast MediaInfo (line 156). This MediaInfo is then used to process a Load Request on lines 180 to 186. You cannot change the way it loads the source (unless you do a proper feature pull request to this repo and get it approved), but you can probably process a load request on your own.

I cannot give you the exact code right now, but a solution would be to introduce the cast API to your own sender application (load the cast framework), connect to the existing castSession, then create your own MediaInfo with a modified .mp4 source, then load it into the castSession similarly to how it's done in the plugin. For inspiration, check Google's guide, specifically the Media Control part for loading in requests. This could probably achieve what you are asking for.

As far as I understand, the plugin does not currently support changing sources in any other way than changing them in the player, so you need to go about it this way. But I'm not an expert here and I have not tried doing this myself as I have not had the need to change an active source given to the cast device yet.

leomelki commented 3 years ago

Ok, i'll try to override videojs methods to make this plugin think that another source is playing but if it doesnt work, i'll do as you said.

Thank you a lot !

(i'll update this post once done)

leomelki commented 2 years ago

I made it work by overriding a function like this :

        this.player.currentSources = () => {
          return [
            {
              src: my_link`,
              type: 'video/mp4'
            }
          ]
        };