How to handle POST method in AudioPlaybackAgent
Hi Friends,
I am trying to create an audio player which can play/pause song from remote location. Also it should be able to go to the next/previous track. I am also using [URL="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.begingetrequeststream.aspx"]POST [/URL]method to get the media URL from the remote location as a response. The player is working perfect when the application is running in foreground. But when the application goes in background(or not running) the [B]AudioPlaybackAgent [/B] can't handle the POST method response.
What I want is that when the [B]AudioPlaybackAgent [/B] is playing the song I should be able to go the next/previous track by using the UVC. I debug and found that when I request a POST method the control comes till [B]GetRequestStreamCallback[/B] and doesn't go any further i.e. to [B]GetResponseCallback[/B].
I have also checked that if I have a list of media URLs then I can set it in a ListBox class and by using the UVC I can change the track, but in my case I am using POST method for security purpose, which gives a new URL each time I request and expires later on.
I have posted this issue on [URL="http://social.msdn.microsoft.com/Forums/en-US/wpdevelop/thread/1c6b9e52-537b-4cee-84fa-e8ccb4b4a3c3"]MSDN [/URL] long back, but till now no response.
Please suggest me if there is any alternate solution.
Re: How to handle POST method in AudioPlaybackAgent
Hello somnathbanik,
Are you hosting your playlist logic in your agent project? if so, Are you using a Webclient or HttpWebRequest ?
A common error is to start a webrequest and then call NotifyComplete() on another thread which freezes the process.
Re: How to handle POST method in AudioPlaybackAgent
[QUOTE=WPMorocco;911169]Hello somnathbanik,
Are you hosting your playlist logic in your agent project?
[/QUOTE]
Regarding playlist, I don't have any ready playlist for the agent. What I have is a list of code(ID) which is pass(each code, each time) as a parameter in the POST method and get the audio URL as response. I need to get these URLs every time I click the next/previous key, cause these URLs are volatile and expires after some time. So I can't store these URLs and need to get a fresh URL every time.
[QUOTE]
if so, Are you using a Webclient or HttpWebRequest ?
A common error is to start a webrequest and then call NotifyComplete() on another thread which freezes the process.[/QUOTE]
I am using [B]HttpWebRequest [/B] in the POST method. I am not sure about the process freezing, but the response does comes to [B]GetRequestStreamCallback [/B] but doesn't go further to [B]GetResponseCallback[/B].
One thing that I would like to add is even when the response doesn't comes back to [B]GetResponseCallback[/B], Audio Agent keeps playing the current song. Does it mean that the agent is live?
Re: How to handle POST method in AudioPlaybackAgent
Is [url]http://social.msdn.microsoft.com/Forums/en-US/wpdevelop/thread/1c6b9e52-537b-4cee-84fa-e8ccb4b4a3c3[/url] your question?
Even if you are bound to that strange XML for the initial phase, you could try parsing it in advance, get the real URL-s, and put them into a List<AudioTrack>.
Networking in AudioPlaybackAgent does not seem to be a safe idea because of the runtime restriction.
Re: How to handle POST method in AudioPlaybackAgent
Thanks wizard_hu_
[QUOTE=wizard_hu_;911176]Is [url]http://social.msdn.microsoft.com/Forums/en-US/wpdevelop/thread/1c6b9e52-537b-4cee-84fa-e8ccb4b4a3c3[/url] your question?
[/QUOTE]
Yes, this is my question, I have added in #1.
[QUOTE]
Even if you are bound to that strange XML for the initial phase, you could try parsing it in advance, get the real URL-s, and put them into a List<AudioTrack>.
Networking in AudioPlaybackAgent does not seem to be a safe idea because of the runtime restriction.[/QUOTE]
The XML is a sample to demonstrate what I am looking form that XML, actual XMLs has more tags. Yes, initially I though of this tricks. But what if I have 50 items, in that case I need to perform POST method 50 times continuously. Also even if I get the audio URLs any how and put it in the [B]AudioTrack[/B], the URLs will get expire after 5 min(time set in server to get expire). So before I complete my first track and go to the next one, the URls will get expired. So I need to get fresh URLs, and to get a fresh URL I need to perform POST method, and thus the problem comes again. But there is no issue performing this task when the app is running in foreground.
Re: How to handle POST method in AudioPlaybackAgent
Yes, initially I was going to ask if the links expire, just forgot that, sorry. In that case I would go for AudioStreamingAgent. Then you can experiment with networking in MediaStreamSource. Basic streamer example is here: [url]http://code.msdn.microsoft.com/wpapps/Background-Audio-Streamer-e85b8deb[/url], MediaStreamSource implementation notes: [url]http://msdn.microsoft.com/en-us/library/hh180779(v=vs.95).aspx[/url], interesting example implementation with mp3 support: [url]https://github.com/loarabia/ManagedMediaHelpers[/url]
Re: How to handle POST method in AudioPlaybackAgent
I do not know I understand your query correctly as I had to be very quick before rushing somewhere, but have you taken a look at this [url]http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202978(v=vs.105).aspx[/url]
Re: How to handle POST method in AudioPlaybackAgent
[QUOTE=Symbian_Neil;911182]I do not know I understand your query correctly as I had to be very quick before rushing somewhere, but have you taken a look at this [url]http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202978(v=vs.105).aspx[/url][/QUOTE]
Yes, I am following this article. I have no problem playing background audio, rather my problem is handling POST method in [B]AudioPlayer.cs[/B] file.
Re: How to handle POST method in AudioPlaybackAgent
[QUOTE=wizard_hu_;911181]Yes, initially I was going to ask if the links expire, just forgot that, sorry. In that case I would go for AudioStreamingAgent. Then you can experiment with networking in MediaStreamSource. Basic streamer example is here: [url]http://code.msdn.microsoft.com/wpapps/Background-Audio-Streamer-e85b8deb[/url], MediaStreamSource implementation notes: [url]http://msdn.microsoft.com/en-us/library/hh180779(v=vs.95).aspx[/url], interesting example implementation with mp3 support: [url]https://github.com/loarabia/ManagedMediaHelpers[/url][/QUOTE]
Though I played streaming audio using AudioStreamingAgent, but never tried to operate POST method in it. I need to see this part if it can get the POST method response.
Re: How to handle POST method in AudioPlaybackAgent
[QUOTE=somnathbanik;911183]Yes, I am following this article. I have no problem playing background audio, rather my problem is handling POST method in [B]AudioPlayer.cs[/B] file.[/QUOTE]Do not overrate POST, from the response point of view it does not differ from GET. To me the problem seems to be that AudioPlaybackAgent and its playlist requires the URL-s in advance.
Feel free to correct me, I have absolutely no experience with these API-s, just reading the docs.
Re: How to handle POST method in AudioPlaybackAgent
[QUOTE=wizard_hu_;911186]Do not overrate POST, from the response point of view it does not differ from GET.[/QUOTE]
Yes I agree and our aim is to get the response from the web request, may be with POST or GET.
[QUOTE]
To me the problem seems to be that AudioPlaybackAgent and its playlist requires the URL-s in advance.
[/QUOTE]
Not always, even if you don't add the list of tracks in [B]AudioTrack[/B], we can create the playlist in a separate list class and play any track by calling the [B]GetPreviousTrack()[/B] and [B]GetNextTrack()[/B] method like this
[QUOTE] AudioTrack track = null;
track = new AudioTrack(parameters)
[/QUOTE]
Re: How to handle POST method in AudioPlaybackAgent
[QUOTE=wizard_hu_;911186]Do not overrate POST, from the response point of view it does not differ from GET. [/QUOTE]
Hi wizard_hu_,
Just for my satisfaction I tried a web request in the [B]AudioPlayer.cs[/B] class. I called [B]WebRequest[/B] calss inside [B]AudioTrack GetNextTrack()[/B] and I got the response.
[QUOTE]
private AudioTrack GetNextTrack()
{
WebRequest request = WebRequest.Create("http://mydomain.com/feeds/internetcheck.php");
request.BeginGetResponse(new AsyncCallback(this.ResponseCallback), request);
}
[/QUOTE]
[QUOTE]
private void ResponseCallback(IAsyncResult asynchronousResult)
{
try
{
var request = (HttpWebRequest)asynchronousResult.AsyncState;
using (var resp = (HttpWebResponse)request.EndGetResponse(asynchronousResult))
{
using (var streamResponse = resp.GetResponseStream())
{
using (var streamRead = new StreamReader(streamResponse))
{
string responseString = streamRead.ReadToEnd();
if (responseString == "SUCCESS")
{
// if statement executes
}
else
{
}
}
}
}
}
catch (WebException ex)
{
}
}
[/QUOTE]
This works perfect even when the application is not running and I just use the UVC to go to the next/previous track.
But the same technique is not working for POST method. No idea why :(
Re: How to handle POST method in AudioPlaybackAgent
I just tried using the same technique on [B]AudioStreamingAgent[/B], its the same issue. The regular web request like in #12 is working but not the POST method.
strange behavior, don't find any reason for this :(
Re: How to handle POST method in AudioPlaybackAgent
Have you tried making a POST using WebClient instead of HttpWebRequest?
Re: How to handle POST method in AudioPlaybackAgent
I still have the same issue. Any help please.