kakone / GoogleCast

Implementation of the Google Cast protocol (.NET Standard 2.0 library)
GNU General Public License v3.0
143 stars 22 forks source link

Status always null Sender.GetChannel<IMediaChannel>().Status #2

Closed roberthardesty closed 6 years ago

roberthardesty commented 7 years ago

Greetings!

First off this is an awesome project, very modern and clean code. I am working on a .Net Core 2.0 Console service that utilizes MQTT for communications and acts as a hub for much of my home automation. I've been attempting to add a chromecast project to the service that utilizes this library. Using the example provided I've been able to connect and Play media, however, before attempting to execute other commands such as PauseAsync() and StopAsync() I check an IsStopped boolean just like in the example.

 public bool IsStopped
        {
            get
            {
                var mediaChannel = _sender?.GetChannel<IMediaChannel>();
                return (mediaChannel?.Status == null || !String.IsNullOrEmpty(mediaChannel.Status.FirstOrDefault()?.IdleReason));
            }
        }

When doing so the mediaChannel.Status is always null. When I do _sender.GetStatuses() I get two entries in the Dictionary. One with Key = "urn:x-cast:com.google.cast.receiver" and the other Key = "urn:x-cast:com.google.cast.media" both with null values.

Is there something I'm missing that's happening in the example?

kakone commented 7 years ago

Strange... It should not be null when the media is playing. When you call the PlayAsync() method, what is the result of the async operation (it should return a not null MediaStatus) ?

Marcus-L commented 7 years ago

@roberthardesty - are you checking IsStopped from a different client/sender than you are starting the media playing from? (or different thread?)

If you are, then Status will be null. I submitted PR #7 which allows you to call GetStatusAsync() on the receiver channel to get the receiver status from a different client, which may help you if this is the case.

kakone commented 7 years ago

Now, there are some GetStatusAsync methods on the ReceiverChannel (and also on the MediaChannel but I forgot to test it). You can call these methods to really know the current status.

ghost commented 6 years ago

When I call GetStatusAsync, the method never returns (and throw a Timeout exception after a long time).

kakone commented 6 years ago

Fixed in version 1.6.4.