-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I tell when an app stops casting? #84
Comments
Not sure if this is what you're looking for, but you can register a listener for new 'cast' (receiver) status updates ?? In the code you linked to, you can add def __init__(self, device):
self.device = device
self.thumbnail = ""
self.sendDeviceStatus()
self.device.media_controller.register_status_listener(self)
self.device.register_status_listener(self) # Register for receiver status updates.
def new_cast_status(self, new_status):
""" Called when a new status received from the Chromecast. """
if new_status.app_id != "CC1AD845":
pass # Your code to turn off your speakers can go here. Note that you may want to launch the app on the receiver BEFORE registering the cast/receiver status listener. Otherwise you might end up turning off your speakers before you've started playing anything due to the status being updated for whatever reason. Hope that helps. P.s. There's also a listener for Network Connection Status updates as well: def __init__(self, device)
self.device.register_connection_listener(self)
def new_connection_status(self, new_status):
# new_status.status will be one of the CONNECTION_STATUS_ constants defined in the
# socket_client module.
if new_status.status == CONNECTION_STATUS_DISCONNECTED:
pass # Your code to turn off your speakers here. |
Hello, I am trying the same. I am not sure, I implemented your suggestion correctly: def getDeviceNamed(name): def on_mqtt_connect(client, userdata, flags, rc): def on_message(command,device): try:
except:passclass DeviceStatusUpdater:
print ("Device discovery...") myDevices is a list of Chromecast devices (class DeviceStatusUpdater)we can now send a messagecmd=['set_volume', '33'] or get the Titleprint(myDevices[0].sendDeviceStatus) from time import sleep while True: What happens is, that I get this output: Followed by the output of sendDeviceStatus() But when changing the status of the chromecast (play, pause, ...) only new_cast_status is only called upon launch of the script. Also: What could be the error of the message Regards, |
I'm really new the python so sorry if this is obvious!
I'm using the code from here: https://www.reddit.com/r/homeautomation/comments/4fc01z/quick_question_for_openhab_users/d28vnc4 to hook up to openhab.
What I want to happen is when I cast something to a chromecast I want me speakers to turn on, and turn off when I stop casting.
The issue I'm having is that the following code:
` self.device.media_controller.register_status_listener(self)
`
doesn't appear to execute when the app_id gets set to None. Is there another "event" I can hook up to so I know when the cast has stopped?
Sorry, I know this is a terrible way to reach out for help, but I didn't want to message you on reddit, and wasn't sure where else to ask!
The text was updated successfully, but these errors were encountered: