alxhotel / chromecast-api

:tv: Chromecast Node.js module
MIT License
155 stars 49 forks source link

If running app in not supported fallback to DefaultMediaReceiver #66

Open FrancescoCioria opened 3 years ago

FrancescoCioria commented 3 years ago

I noticed that currently we can control only the Youtube app. In my opinion there is no reason not to enable the media controls (play, pause, volume, seek ...) for any other apps playing medias.

I edited your code to fallback to DefaultMediaReceiver for unknown apps, and indeed I was able to play, pause, change volume etc for Spotify, Amazon Prime Video and Netflix.

I simply edited this part

      const filtered = sessions.filter((session) => {
        return (app)
          ? session.appId === app.APP_ID
          : SUPPORTED_APP_IDS.includes(session.appId)
      })

      const session = filtered.shift();

      if (session) {
        app = app || SUPPORTED_APPS[session.appId];
        this.client.join(session, app, callback)
      } else if (app) {
        this.client.launch(app, callback)
      } else {
        callback(new Error('no session started'))
      }

to:

      const session = sessions.shift();

      if (session) {
        app = app || SUPPORTED_APPS[session.appId] || DefaultMediaReceiver;
        this.client.join(session, app, callback)
      } else if (app) {
        this.client.launch(app, callback)
      } else {
        callback(new Error('no session started'))
      }
guyluz11 commented 11 months ago

Hey @FrancescoCioria does that still works for you?.

I am trying to create requests like you have mentioned "Spotify, Amazon Prime Video and Netflix" in another programming language named Dart.

If you can share what kNamespace (cast:com.google.cast.receiver) did you used and how is your request looks like

{
    app: "DefaultMediaReceiver",
    type: "MEDIA",
    media: {
      url: "http://test.com/media.mp3",
      contentType: "audio/mp3", // optional if type can be infered from url file
      streamType: "BUFFERED", // optional unless you want to send LIVE instead
    }
}

it will be awesome.

FrancescoCioria commented 11 months ago

Hi @guyluz11 Honestly I stopped using this a bit more than a year ago but at that time it was still working

I was looking now at my own code and apparently I released a lib on NPM with the code I was using to control the medias running on the chromecast (I had totally forgot 😅): https://github.com/FrancescoCioria/chromecast-media-controls-api

I cannot really help you on the low-level chromecast api because I relied on another library called castv2-client (https://www.npmjs.com/package/castv2-client) but I'm pretty sure I only used the default DefaultMediaReceiver

Hope this helps

guyluz11 commented 11 months ago

Ok thanks for the reply. Will look