pychromecast icon indicating copy to clipboard operation
pychromecast copied to clipboard

Not receiving events and always getting the same media status.

Open felipelerena opened this issue 10 years ago • 6 comments

It's happening with every video, this is what happens all along the Big buck bunny video from example.py

Please let me know if I can help you further to detect this issue

Media status MediaStatus(current_time=0.583322, content_id=None, content_type=None, duration=0, stream_type=None, idle_reason=None, media_session_id=1, playback_rate=1, player_state=u'PLAYING', supported_media_commands=15, volume_level=1, volume_muted=False, media_customData=None) Media status MediaStatus(current_time=0.583322, content_id=None, content_type=None, duration=0, stream_type=None, idle_reason=None, media_session_id=1, playback_rate=1, player_state=u'PLAYING', supported_media_commands=15, volume_level=1, volume_muted=False, media_customData=None)

felipelerena avatar Nov 05 '14 04:11 felipelerena

If the state of the chromecast has not changed between the two moments you printend it, the MediaStatus should be the same. Reasons for the MediaStatus to change would be for example if you send the PAUSE, SEEK or STOP command. If you want to know what the current time is when the state is PLAYING you will have to calculate it. I have plans to add support for a getCurrentTime() method to the MediaStatus class but currently have no ETA. It would be something similar to: seconds_since_last_update = (now()-mediastatus.created).seconds return current_time if plater_state != 'PLAYING' else return current_time + seconds_since_last_update

balloob avatar Nov 05 '14 04:11 balloob

Ok. But I press pause on my remote control on the tv and nothing happens. Shouldn't I get an event? If I press pause on the TV the video should pause right? Because I'm not getting any event

felipelerena avatar Nov 05 '14 10:11 felipelerena

Does the pause button on your remote control also control the Chromecast? As in, do you see the video get paused?

What if you call pause from pychromecast, the MediaStatus should get updated then.

balloob avatar Nov 05 '14 14:11 balloob

It's not pausing the video on the chromecast (but I'm sure that anynet/HDMI-CIC works, i.e. Youtube). It works if I send the same video to the same chromecast using Bubble UPnP It does pause if I send the pause command from pychromecast.

felipelerena avatar Nov 05 '14 14:11 felipelerena

Hello, I think I'm experiencing similar problems. I'm using the first (and only?) Chromecast Audio device.

In my case I'm playing a sequence of songs. My intention is to play the next song when I receive the media status update that the previous song is finished.

When the previous song finishes, by enabling logging, this message is received from the Chromecast

DEBUG:pychromecast.socket_client:Received: Message urn:x-cast:com.google.cast.media from 46e5ee83-49f8-4a1a-b3d7-178af713f74f to *: {'type': 'MEDIA_STATUS', 'status': [{'mediaSessionId': 7, 'playbackRate': 1, 'playerState': 'IDLE', 'currentTime': 0, 'supportedMediaCommands': 274447, 'volume': {'level': 1, 'muted': False}, 'currentItemId': 7, 'idleReason': 'FINISHED'}], 'requestId': 0}

This causes the internal media_controller status object to be updated to playerState = IDLE idleReason = FINISHED contentId = previous track

Then I submit the next track

[ Wed Sep 5 00:49:05 2018 ] Playing http://192.168.1.90:8000/Clip%204.ogg.flac

INFO:pychromecast.controllers:Not launching app CC1AD845 - already running DEBUG:pychromecast.socket_client:Sending: Message urn:x-cast:com.google.cast.media from sender-0 to 46e5ee83-49f8-4a1a-b3d7-178af713f74f: {'media': {'contentId': 'http://192.168.1.90:8000/Clip%204.ogg.flac', 'streamType': 'BUFFERED', 'contentType': 'audio/flac', 'metadata': {}}, 'type': 'LOAD', 'currentTime': 0, 'autoplay': True, 'customData': {}, 'requestId': 6, 'sessionId': '46e5ee83-49f8-4a1a-b3d7-178af713f74f'}

and the following message is received immediately

DEBUG:pychromecast.socket_client:Received: Message urn:x-cast:com.google.cast.media from 46e5ee83-49f8-4a1a-b3d7-178af713f74f to *: {'type': 'MEDIA_STATUS', 'status': [{'mediaSessionId': 8, 'playbackRate': 1, 'playerState': 'IDLE', 'currentTime': 0, 'supportedMediaCommands': 274447, 'volume': {'level': 1, 'muted': False}, 'media': {'contentId': 'http://192.168.1.90:8000/Clip%204.ogg.flac', 'streamType': 'BUFFERED', 'contentType': 'audio/flac', 'metadata': {}}, 'currentItemId': 8, 'extendedStatus': {'playerState': 'LOADING', 'media': {'contentId': 'http://192.168.1.90:8000/Clip%204.ogg.flac', 'streamType': 'BUFFERED', 'contentType': 'audio/flac', 'metadata': {}}}, 'repeatMode': 'REPEAT_OFF'}], 'requestId': 0}

note that the playerState is still IDLE but there's an extendedStatus structure that is completely ignored by the library containg an playerState LOADING update. This way the internal status is updated this way

playerState = IDLE idleReason = FINISHED contentId = next track

and this new status is delivered to the registered listeners, which of course is totally misleading.

Best Regards, Carlo.

ygmarchi avatar Sep 04 '18 23:09 ygmarchi

Naively, by inserting the following code in the update method in media.py things get much better:

    extended_status_data = status_data.get('extendedStatus')
    if extended_status_data:
        data ['status'] = [extended_status_data]
        self.update (data)

ygmarchi avatar Sep 05 '18 00:09 ygmarchi