-
Notifications
You must be signed in to change notification settings - Fork 5
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
AddTrackToQueue throwing invalidOperationException #1
Comments
402 is Payment Required no? Are you adding a track from Spotify or somewhere online? Or are you trying to add a track that is on your network/NAS? The AddTrackToQueueAsync method is definitely a bit wobbly :-). If I remember correctly I have only ever got it working with files that were on my NAS. Could you provide a snipit of the line of code when you make the call as well. Thanks. I'll take a look into this more next week. Glad you are getting some benefit from it :-) |
The UPnP docs say 402 is invalid argument. The URI comes from my favorites and is a Sirius XM channel. FYI, giving it a URI from a network share works flawlessly, thank-you! Here's my call to the function: gSonosMedia.Res is a string containing: Here's where the exception occurs:
Again, providing the same URI to Intel Device Spy, and invoking the action works. Unfortunately, I can't really see the SOAP call being made by Device Spy to compare it against the SOAP call your library is making. Do you think it could be related to escaping the URI? I did try passing an XML "escaped" URI as a test, but got the same issue. BUT, I'm not really following how the library is handling escaping down in it's guts. Thanks again, for this great library. |
Are you saying the following line throws the exception?:
Could you provide the full exception? i.e. the stack trace/ToString() of the exception thrown. Thanks :-). This is a little hard for me to debug as obviously I will never have a file at location:
If AddUriToQueueResponseFactory.CreateFor is the problem maybe worth running the code and stepping through the method to see what exactly the problem is. I'm probably making an assumption about what will be returned in the response, assuming something will be there and it isn't. What is the raw XML response you get back? If you need an easy way to run that method and debug just modify and run of the integration tests in AvTransportServiceTest.AddTrackToQueueAsync. I would be very keen to see what is going on. I've struggled a little in some places with adding items to the queue, as you can problem see by looking at the IntTests for AvTransportServiceTest.AddTrackToQueueAsync :-). |
That is the line that throws the exception. It exception itself says "Sequence contains no elements". When I examine the Data property I see: Enumeration yielded no results. Here's the stack trace:
The parameters passed to the CreateFor method are: ActionXNamespace: urn:schemas-upnp-org:service:AVTransport:1 Tracing through, it looks like it's actually this statement in the CreateFor method that's generating the exception I'm guessing that since the return from the Sonos was an error, it's not finding the XML element it wants in the response, so it's throwing the error. The real problem is likely is further upstream. Stepping through UpnpRequestContentFactory.CreateFor, I see the following content string being returned from the CreateSoapMessage method: I'm betting that the "EnquedURI" element needs to have the '&' characters escaped. |
That was it!!!!! In CreateSoapMessageBody, I changed two lines in the foreach loop to replace the ampersand character with the escaped version. I tried to put the actual code here, but the post didn't show the actual change (it thought I was escaping the string). I found a post which referred me to the XML Specification where this is all described. https://stackoverflow.com/questions/6898259/when-is-it-required-to-escape-characters-in-xml Typically, when I escape strings I use one of the built-in .net functions. In this case, I didn't want to introduce more variability and just dealt with the "&". |
Turns out that I needed to deal with more than just the "&". I took a few liberties and changed the CreateSoapMessageBody method to look like this: ` private static string CreateSoapMessageBody(SoapAction sa, UpnpArgumentList list)
Every argument is now escaped and things are working fine! |
I've put up a new version (1.1.0) on nuget with your fix. Thanks for spotting that I wasn't escaping the soap argument values. I also added a simple AddQueueTrackAsync method to SonosController that at the moment just calls through to the AV transport. Out of interest when you add the particular track you were talking about does it add the track and display the correct meta data in a Sonos controller app (on your phone, PC etc.)? When I add it it just comes up with the name as "x-sonosapi-hls:r%3athepulse?sid=37&flags=8480&sn=1" (and it doesnt play) obviously because I have no Sirius account with access. |
It does show the metadata (and artwork) properly. FYI, I also extended the AVT service to include the SetAVTransportURI method. I can send you the code if you like, but it's a very short method modeled after your other methods. Have you considered adding support for event subscriptions? At the moment, I poll media players for status. I was thinking it might be more efficient to just respond to events. Finally, have you noticed a memory leak using the Intel UPnP library for device discovery. Memory use grows overtime until it simply consumes all available memory. I stopped using the intel library for SSDP because of that years ago. I currently use the RSSDP library for device discovery. |
I'have noticed that too... and back those days I switched to an other sonos nuget, but that hat only a very small feature set. Does the memory leak onyl show up when I use discovery? So when I just controll the speakers by creating a controller over the IP-address, there is no memory leak? |
Currently I`m trying to add music from Spotify (Tracks an Playlists) to Sonos-Queue. But when I add a track to queue I can only see the provider uri in the sonos app, it does not show art and it does not show a playing position... is that correct? Scenario:
Am I doing something wrong? |
You're a little more ambitious than I've been. I only support MP3 files on my local LAN and Sonos Favorites in my controller. Both of those show the artwork (and play position for the MP3). Have you tried using UPnP Device Spy to see if there's any metadata required when the Sonos app itself tries to play the track? On your question regarding UPnP memory leak. I was having that issue when I was using the Intel UPnP library and tools to build a generic UPnP controller. I traced it back to discovery. However, using RSSDP to do discovery solved that problem. I no longer have a memory leak. |
Cool... thanks a lot... at the moment I have the problem, that I cannot connect to multiple spotify accounts at the same time... as soon as this is solved, I'll try to port over my Sonos-integration to this nuget and then I'll test it... I dont need discovery.... so fingers crossed :-) |
Does the memory leak onyl show up when I use discovery? So when I just controll the speakers by creating a controller over the IP-address, there is no memory leak? |
RSSDP, are you talking about: https://www.nuget.org/packages/Rssdp/ ? :-) |
That's the one!!!!!! |
Very nice package! Thanks for putting it together. I'm trying to queue up an item from Sonos favorites, but the call to AddTrackToQueueAsync returns System.InvalidOperationException: 'Sequence contains no elements'. After stepping through the code with a debugger, it looks like the call to InvokeFuncWithResultsAsync is returning an error 402. I'm using the defaults for desiredFirsttrackNumberEnqueued, and enqueueAsNext, this URL:
x-sonosapi-hls:r%3athepulse?sid=37&flags=8480&sn=1
Interestingly, when I execute the same action with the same parameters through Intel's Device Spy, the invocation completes successfully, and the media item is queued.
I'd appreciate any help you can provide.
The text was updated successfully, but these errors were encountered: