×

Discussion Board

Results 1 to 15 of 15
  1. #1
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,349

    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 POST 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 AudioPlaybackAgent can't handle the POST method response.
    What I want is that when the AudioPlaybackAgent 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 GetRequestStreamCallback and doesn't go any further i.e. to GetResponseCallback.

    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 MSDN long back, but till now no response.

    Please suggest me if there is any alternate solution.

  2. #2
    Nokia Developer Champion
    Join Date
    Jul 2012
    Posts
    88

    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.

  3. #3
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,349

    Re: How to handle POST method in AudioPlaybackAgent

    Quote Originally Posted by WPMorocco View Post
    Hello somnathbanik,
    Are you hosting your playlist logic in your agent project?
    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.
    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.
    I am using HttpWebRequest in the POST method. I am not sure about the process freezing, but the response does comes to GetRequestStreamCallback but doesn't go further to GetResponseCallback.

    One thing that I would like to add is even when the response doesn't comes back to GetResponseCallback, Audio Agent keeps playing the current song. Does it mean that the agent is live?
    Last edited by somnathbanik; 2013-02-13 at 08:44. Reason: added

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,572

    Re: How to handle POST method in AudioPlaybackAgent

    Is http://social.msdn.microsoft.com/For...a-e8ccb4b4a3c3 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.

  5. #5
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,349

    Re: How to handle POST method in AudioPlaybackAgent

    Thanks wizard_hu_

    Quote Originally Posted by wizard_hu_ View Post
    Yes, this is my question, I have added in #1.
    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.
    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 AudioTrack, 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.
    Last edited by somnathbanik; 2013-02-13 at 10:39. Reason: added

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,572

    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: http://code.msdn.microsoft.com/wpapp...eamer-e85b8deb, MediaStreamSource implementation notes: http://msdn.microsoft.com/en-us/libr...(v=vs.95).aspx, interesting example implementation with mp3 support: https://github.com/loarabia/ManagedMediaHelpers

  7. #7
    Nokia Developer Moderator
    Join Date
    Oct 2006
    Location
    Finland
    Posts
    4,492

    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 http://msdn.microsoft.com/en-us/libr...v=vs.105).aspx

  8. #8
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,349

    Re: How to handle POST method in AudioPlaybackAgent

    Quote Originally Posted by Symbian_Neil View Post
    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 http://msdn.microsoft.com/en-us/libr...v=vs.105).aspx
    Yes, I am following this article. I have no problem playing background audio, rather my problem is handling POST method in AudioPlayer.cs file.

  9. #9
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,349

    Re: How to handle POST method in AudioPlaybackAgent

    Quote Originally Posted by wizard_hu_ View Post
    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: http://code.msdn.microsoft.com/wpapp...eamer-e85b8deb, MediaStreamSource implementation notes: http://msdn.microsoft.com/en-us/libr...(v=vs.95).aspx, interesting example implementation with mp3 support: https://github.com/loarabia/ManagedMediaHelpers
    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.

  10. #10
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,572

    Re: How to handle POST method in AudioPlaybackAgent

    Quote Originally Posted by somnathbanik View Post
    Yes, I am following this article. I have no problem playing background audio, rather my problem is handling POST method in AudioPlayer.cs file.
    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.

  11. #11
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,349

    Re: How to handle POST method in AudioPlaybackAgent

    Quote Originally Posted by wizard_hu_ View Post
    Do not overrate POST, from the response point of view it does not differ from GET.
    Yes I agree and our aim is to get the response from the web request, may be with POST or GET.
    To me the problem seems to be that AudioPlaybackAgent and its playlist requires the URL-s in advance.
    Not always, even if you don't add the list of tracks in AudioTrack, we can create the playlist in a separate list class and play any track by calling the GetPreviousTrack() and GetNextTrack() method like this

    AudioTrack track = null;
    track = new AudioTrack(parameters)

  12. #12
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,349

    Re: How to handle POST method in AudioPlaybackAgent

    Quote Originally Posted by wizard_hu_ View Post
    Do not overrate POST, from the response point of view it does not differ from GET.
    Hi wizard_hu_,

    Just for my satisfaction I tried a web request in the AudioPlayer.cs class. I called WebRequest calss inside AudioTrack GetNextTrack() and I got the response.

    private AudioTrack GetNextTrack()
    {

    WebRequest request = WebRequest.Create("http://mydomain.com/feeds/internetcheck.php");
    request.BeginGetResponse(new AsyncCallback(this.ResponseCallback), request);
    }
    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)
    {

    }
    }
    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
    Last edited by somnathbanik; 2013-02-14 at 09:59. Reason: added

  13. #13
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,349

    Re: How to handle POST method in AudioPlaybackAgent

    I just tried using the same technique on AudioStreamingAgent, 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

  14. #14
    Nokia Developer Champion
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    477

    Re: How to handle POST method in AudioPlaybackAgent

    Have you tried making a POST using WebClient instead of HttpWebRequest?

  15. #15
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,349

    Re: How to handle POST method in AudioPlaybackAgent

    I still have the same issue. Any help please.

Similar Threads

  1. HTTP Post method
    By acool9 in forum Windows Phone General
    Replies: 8
    Last Post: 2012-04-13, 09:56
  2. how to handle a POST request in a HTTP Server
    By yioyioyi in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2010-12-14, 07:24
  3. This is the right method to use POST?
    By gardner_xu in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2009-04-08, 06:52

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •