Tapanila / SharpCaster

Chromecast C# SDK for .net standard 2.0
MIT License
304 stars 49 forks source link

MediaChannel "Error" Event(?) not implemented #309

Closed RobertK66 closed 1 month ago

RobertK66 commented 1 month ago

hi, when playing around with my "public available CDs" (tracks showing to internet MP3 streams) I suddenly encountered this:

Sharpcaster.Channels.MediaChannel: Trace: RECEIVED: {"type":"ERROR","detailedErrorCode":104,"itemId":15}
Sharpcaster.ChromecastClient: Error: The received Message of Type 'ERROR' can not be converted to its response Type. An implementing IMessage class is missing!

after some checking of the URLs and playing them in the web browser the error disappeared ... the log also showed sometimes this LOAD_ERROR with the same error code.

Sharpcaster.Channels.MediaChannel: Trace: RECEIVED: "requestId":1870045973,"type":"LOAD_FAILED","detailedErrorCode":104,"itemId":16}

not sure what's going on here but definitely we do get a 'Message' (Event?) that is not yet translatable. Tried to find doku but I am still not really comfortable with this protobuffer protocol.

Tapanila commented 1 month ago

Very interesting.

Error codes can be found here and 104 is: The media resource indicated by the src attribute was not suitable.

https://developers.google.com/android/reference/com/google/android/gms/cast/MediaError.DetailedErrorCode

It seems like there's ERROR_TYPE_ERROR which I haven't implemented at all. It's bit hard to implement it blindly but I will take a look into reproducing it as test case first

RobertK66 commented 1 month ago

The whole sequence starting with queue-load (there was another queue playing before) was:

Sharpcaster.Channels.MediaChannel: Trace: SENT    : 20f743f4-0a0d-4cd4-8871-8e3a481d0355: {"items":[{"media":{"contentId":"https://audionautix.com/Music/AwayInAManger.mp3","streamType":2,"contentType":"audio/mp4","metadata":{"metadataType":0,"title":"AwayInAManger","subtitle":null,"images":null},"duration":null,"customData":null},"autoPlay":null},{"media":{"contentId":"https://audionautix.com/Music/CarolOfTheBells.mp3","streamType":2,"contentType":"audio/mp4","metadata":{"metadataType":0,"title":"CarolOfTheBells","subtitle":null,"images":null},"duration":null,"customData":null},"autoPlay":null},{"media":{"contentId":"https://audionautix.com/Music/JoyToTheWorld.mp3","streamType":2,"contentType":"audio/mp4","metadata":{"metadataType":0,"title":"JoyToTheWorld","subtitle":null,"images":null},"duration":null,"customData":null},"autoPlay":null}],"repeatMode":"REPEAT_OFF","sessionId":"20f743f4-0a0d-4cd4-8871-8e3a481d0355","requestId":1870045973,"type":"QUEUE_LOAD"}
Sharpcaster.Channels.HeartbeatChannel: Trace: Stopped heartbeat timeout timer
Sharpcaster.Channels.MediaChannel: Trace: RECEIVED: {"type":"MEDIA_STATUS","status":[{"mediaSessionId":4,"playbackRate":1,"playerState":"IDLE","currentTime":0,"supportedMediaCommands":12303,"volume":{"level":1,"muted":false},"currentItemId":1,"idleReason":"INTERRUPTED","extendedStatus":{"playerState":"LOADING","media":{"contentId":"https://audionautix.com/Music/AwayInAManger.mp3","streamType":2,"contentType":"audio/mp4","metadata":{"metadataType":0,"title":"AwayInAManger"},"mediaCategory":"AUDIO"},"mediaSessionId":5}}],"requestId":0}
Sharpcaster.Channels.HeartbeatChannel: Trace: Stopped heartbeat timeout timer
Sharpcaster.Channels.ReceiverChannel: Trace: RECEIVED: {"requestId":0,"status":{"applications":[{"appId":"46C1A819","displayName":"Receiver for AirConnect & CastBridge","isIdleScreen":false,"launchedFromCloud":false,"namespaces":[{"name":"urn:x-cast:com.google.cast.debugoverlay"},{"name":"urn:x-cast:com.google.cast.cac"},{"name":"urn:x-cast:com.google.cast.media"}],"sessionId":"20f743f4-0a0d-4cd4-8871-8e3a481d0355","statusText":"Receiver for AirConnect & CastBridge","transportId":"20f743f4-0a0d-4cd4-8871-8e3a481d0355"}],"volume":{"controlType":"master","level":0.10499999672174454,"muted":false,"stepInterval":0.03125}},"type":"RECEIVER_STATUS"}
Sharpcaster.Channels.HeartbeatChannel: Trace: Stopped heartbeat timeout timer
Sharpcaster.Channels.ReceiverChannel: Trace: RECEIVED: {"requestId":0,"status":{"applications":[{"appId":"46C1A819","displayName":"Receiver for AirConnect & CastBridge","isIdleScreen":false,"launchedFromCloud":false,"namespaces":[{"name":"urn:x-cast:com.google.cast.debugoverlay"},{"name":"urn:x-cast:com.google.cast.cac"},{"name":"urn:x-cast:com.google.cast.media"}],"sessionId":"20f743f4-0a0d-4cd4-8871-8e3a481d0355","statusText":"Streamen: AwayInAManger","transportId":"20f743f4-0a0d-4cd4-8871-8e3a481d0355"}],"volume":{"controlType":"master","level":0.10499999672174454,"muted":false,"stepInterval":0.03125}},"type":"RECEIVER_STATUS"}
Sharpcaster.Channels.HeartbeatChannel: Trace: Stopped heartbeat timeout timer
Sharpcaster.Channels.MediaChannel: Trace: RECEIVED: {"type":"ERROR","detailedErrorCode":104,"itemId":14}
Sharpcaster.ChromecastClient: Error: The received Message of Type 'ERROR' can not be converted to its response Type. An implementing IMessage class is missing!
'WinUiHomeAudio.exe' (CoreCLR: clrhost): Loaded 'C:\Users\xxxxxxxx\source\repos\HomeAudio\WinUiHomeAudio\bin\x64\Debug\net8.0-windows10.0.22621.0\win-x64\AppX\Microsoft.Win32.Registry.dll'. Symbols loaded.
Sharpcaster.Channels.HeartbeatChannel: Trace: Stopped heartbeat timeout timer
Sharpcaster.Channels.MediaChannel: Trace: RECEIVED: {"type":"MEDIA_STATUS","status":[{"mediaSessionId":5,"playbackRate":1,"playerState":"IDLE","currentTime":0,"supportedMediaCommands":12303,"volume":{"level":1,"muted":false},"currentItemId":14,"loadingItemId":15,"idleReason":"ERROR","extendedStatus":{"playerState":"LOADING","media":{"contentId":"https://audionautix.com/Music/CarolOfTheBells.mp3","streamType":2,"contentType":"audio/mp4","metadata":{"metadataType":0,"title":"CarolOfTheBells"},"mediaCategory":"AUDIO"},"mediaSessionId":5},"queueData":{"repeatMode":"REPEAT_OFF","shuffle":false,"startIndex":0},"repeatMode":"REPEAT_OFF"}],"requestId":0}
Sharpcaster.Channels.HeartbeatChannel: Trace: Stopped heartbeat timeout timer
Sharpcaster.Channels.ReceiverChannel: Trace: RECEIVED: {"requestId":0,"status":{"applications":[{"appId":"46C1A819","displayName":"Receiver for AirConnect & CastBridge","isIdleScreen":false,"launchedFromCloud":false,"namespaces":[{"name":"urn:x-cast:com.google.cast.debugoverlay"},{"name":"urn:x-cast:com.google.cast.cac"},{"name":"urn:x-cast:com.google.cast.media"}],"sessionId":"20f743f4-0a0d-4cd4-8871-8e3a481d0355","statusText":"Receiver for AirConnect & CastBridge","transportId":"20f743f4-0a0d-4cd4-8871-8e3a481d0355"}],"volume":{"controlType":"master","level":0.10499999672174454,"muted":false,"stepInterval":0.03125}},"type":"RECEIVER_STATUS"}
Sharpcaster.Channels.HeartbeatChannel: Trace: Stopped heartbeat timeout timer
Sharpcaster.Channels.ReceiverChannel: Trace: RECEIVED: {"requestId":0,"status":{"applications":[{"appId":"46C1A819","displayName":"Receiver for AirConnect & CastBridge","isIdleScreen":false,"launchedFromCloud":false,"namespaces":[{"name":"urn:x-cast:com.google.cast.debugoverlay"},{"name":"urn:x-cast:com.google.cast.cac"},{"name":"urn:x-cast:com.google.cast.media"}],"sessionId":"20f743f4-0a0d-4cd4-8871-8e3a481d0355","statusText":"Streamen: CarolOfTheBells","transportId":"20f743f4-0a0d-4cd4-8871-8e3a481d0355"}],"volume":{"controlType":"master","level":0.10499999672174454,"muted":false,"stepInterval":0.03125}},"type":"RECEIVER_STATUS"}
Sharpcaster.Channels.HeartbeatChannel: Trace: Stopped heartbeat timeout timer
Sharpcaster.Channels.MediaChannel: Trace: RECEIVED: {"type":"ERROR","detailedErrorCode":104,"itemId":15}
Sharpcaster.ChromecastClient: Error: The received Message of Type 'ERROR' can not be converted to its response Type. An implementing IMessage class is missing!
The thread '.NET TP Worker' (25924) has exited with code 0 (0x0).
The thread '.NET TP Worker' (13016) has exited with code 0 (0x0).
The thread '.NET TP Worker' (23660) has exited with code 0 (0x0).
The thread '.NET TP Worker' (1656) has exited with code 0 (0x0).

I now recognized that I mark the media items as 'audio/mp4' even if they are mp3 but this was/and normally is no issue at all.

RobertK66 commented 1 month ago

I am testing crazy things here: running my WinUI3 App and my ConGUI at the same time and connected to the same device with the same appID - then play a cd from WinUi and then press Next on the ConGUI.....

It works (now) most of the time but until now only with the media from 'https://audionautix.com/Music/...' it sometimes has 'hickups'. Also my device is nearing a state where it needs a power down cycle (this occasionally happens when doing this stuff the device gets very slow in its reaction -> interesting bus and protocol timings for test purpose 😉 ...)

Tapanila commented 1 month ago

created 1.2.1-alpha package. If you can reproduce the problem with that build it might now lead to issues with mediaChannel but the original problem should be fixed.

RobertK66 commented 1 month ago

ok thx. I switched to this release - and could reproduce the error.

Our '.. can not be converted ...' error is fixed. What issues with the media channel do you expect now? I can use the channel after the error with other load and load_queue commands and it seems to work.

RobertK66 commented 1 month ago

It definitively has to do with this URLs:

     "ContentUrl": "https://audionautix.com/Music/AwayInAManger.mp3",
     "ContentUrl": "https://audionautix.com/Music/CarolOfTheBells.mp3",
     "ContentUrl": "https://audionautix.com/Music/JoyToTheWorld.mp3",

it is easy to reproduce here. When I first use them the above error occurs. When I load them in Browser then there seems to be a short 'Player page' doing a 'autoplay' and after that my chromecast device can play the url like all others. So I will remove them from my example...

Tapanila commented 1 month ago

Mainly expecting that you won't be able to catch those errors anywhere. So it's basically eating them.

RobertK66 commented 1 month ago

No prob. I think the rest of the Status messages is consistent with this error. So the receiver/channels go to idle (sometimes with idle reason 'error') after that. The only place where I see it now is the trace and that's ok for this problem where the URL does not deliver a mp3 stream....

Tapanila commented 1 month ago

Added error handling to media channel and wrote a testcase for it. Thanks for the content links that I could use to repeat the problem.

RobertK66 commented 1 month ago

This works excellent now! The queue load tries to play all media, the first 2 entries trigger this error on the new handler and the last one now raises the Exception with the original load request. And now all gets correctly logged on level 'Error'! Thx a lot again.

Tapanila commented 1 month ago

Great to hear and thanks for reporting the issue