kakone / GoogleCast

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

CurrentTime is not updated and cannot get Duration #14

Closed cncb-gh closed 5 years ago

cncb-gh commented 5 years ago

I am playing the sample video (Big Buck Bunny) and MediaStatus.CurrentTime is not updated until the PlayerState is toggled. That is, repeated calls to IMediaChannel.Status result in the same CurrentTime until the video is paused at which point it is updated. Is there a way to get this to update while playing?

Also, it looks like the only way to retrieve the video duration is through MediaStatus.Media.Duration but MediaStatus.Media is null?

Thanks.

kakone commented 5 years ago

You need to call the IMediaChannel.GetStatusAsync() method (only works in version 1.6.4).

cncb-gh commented 5 years ago

This keeps getting in the state where the following exception is thrown when IMediaChannel.GetStatusAsync() is called even after the connection is made and the media starts playing? Thanks for your help.

Value cannot be null.
Parameter name: MediaSessionId

  at GoogleCast.Channels.MediaChannel.SetMediaSessionId (GoogleCast.Messages.Media.MediaSessionMessage message) [0x00007] in <bd0bbdc0a0dc47da8839ff1a146a06c9>:0 
  at GoogleCast.Channels.MediaChannel+<SendAsync>d__6.MoveNext () [0x000bb] in <bd0bbdc0a0dc47da8839ff1a146a06c9>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <43dbbdc147f2482093d8409abb04c233>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <43dbbdc147f2482093d8409abb04c233>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <43dbbdc147f2482093d8409abb04c233>:0 
  at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <43dbbdc147f2482093d8409abb04c233>:0 
  at GoogleCast.Channels.MediaChannel+<GetStatusAsync>d__8.MoveNext () [0x00067] in <bd0bbdc0a0dc47da8839ff1a146a06c9>:0 
kakone commented 5 years ago

Can you share a sample code, I don't reproduce the problem. With the code in the README file, if I do mediaStatus = await mediaChannel.GetStatusAsync(); after the LoadAsync method, it works well.

cncb-gh commented 5 years ago

It appears that an uncaught exception in my StatusChanged event handler was causing this. Sorry about that.

It appears that every time that GetStatusAsync() is called it causes a StatusChanged event to be fired. Also, GetStatusAsync() seems to throw an exception when the player is IDLE. Is this to be expected? How does the IMediaChannel.Status property fit into this? Thanks again.

kakone commented 5 years ago

OK, I see the problem. I'm going to correct it as soon as possible.

kakone commented 5 years ago

It appears that every time that GetStatusAsync() is called it causes a StatusChanged event to be fired

Yes, when we received an updated status message, the Status property is updated, so the StatusChanged event is fired.

GetStatusAsync() seems to throw an exception when the player is IDLE

Fixed in version 1.6.6

cncb-gh commented 5 years ago

I upgraded to v1.6.6 and still seem to get this exception when calling IMediaChannel.GetStatusAsync() when no media is playing:

System.InvalidOperationException

Sequence contains no elements: at System.Linq.Enumerable.First[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x00010]