views:

138

answers:

2

Hi

I tring to stream shoutcast stream in my window phone 7 app

I start an async HttpWebRequest like this

//Init Request

HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://ACommonoShoutCastUrl:8000");

myHttpWebRequest.Headers["Icy-MetaData"] = "1";

myHttpWebRequest.UserAgent = "WinampMPEG/5.09";

myHttpWebRequest.AllowReadStreamBuffering = true;

//Call

 // Create an instance of the RequestState and assign the previous myHttpWebRequest object to its request field.  

RequestState myRequestState = new RequestState();

 myRequestState.request = myHttpWebRequest;

 // Start the asynchronous request.

 IAsyncResult result = (IAsyncResult)myHttpWebRequest.BeginGetResponse(new AsyncCallback(RespCallBack), myRequestState);

The problem is that the CallBack->RespCallBack is never called...

This code worked for me normally in other environments but not on the phone...

I tired also to use WebClient that seems to stream data,

the problem in this case is that it never call the end OpenReadCompleted because of endelss shoutcast stream

Thanks for support

any help would be appreciated

+1  A: 

I just put the following on a page and the callback was called in repsonse to the button click. (I set a break point on the throw statement and it was hit.)

    private HttpWebRequest myHttpWebRequest;

    public MainPage()
    {
        InitializeComponent();
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        //Init Request 
        //The following URI was chosen at random
        myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://yp.shoutcast.com/sbin/tunein-station.pls?id=1377200");
        myHttpWebRequest.Headers["Icy-MetaData"] = "1";
        myHttpWebRequest.UserAgent = "WinampMPEG/5.09";
        myHttpWebRequest.AllowReadStreamBuffering = true;

        // Start the asynchronous request.
        myHttpWebRequest.BeginGetResponse(RespCallBack, myHttpWebRequest);
    }

    private void RespCallBack(IAsyncResult ar)
    {
        throw new NotImplementedException();
    }
Matt Lacey
Hi this code lead to download the tunein-station.pls inside i can find the real stream url for shoutcast:File1=http://78.159.104.182:80Title1=(#1 - 381/700) TechnoBase.FM - 24h Techno, Dance, Trance, House and More - 128k MP3the problem come out when i try to get the stream to play it on phone on the shoutcast server url like http://78.159.104.182:80
BloopDev
+1  A: 

SHOUTcast implements its own protocol so you can't directly access and play it. You can use DownloadStringAsync (you will need a WebClient instance for this) to download the PLS file and read the URL with the help of RegEx.

When you get the URL, you can read the raw audio data by implementing MediaStreamSource and then use a MediaElement to play the contents.

You can find a sample implementation of MediaStreamSource here.

Dennis Delimarsky
I did such kind of operation on shoutcast on android and iphone ios, the problem is that i cannot get the stream back from the shoutcast url (like http://76.76.18.103:8322/) by httpwebrequest so i cannot start the process of searching shoutcast metadata
BloopDev
I am trying to figure that one out as well now. It seems like SHOUTcast is sending some invalid headers or content that cannot be qualified as HttpWebResponse. I am trying to work with a WebClient instance for now.
Dennis Delimarsky
I did successfully by Sync HttpRequest but Windows Phone 7 doesn't permit this. The WebClient raise the progressEvent but inside i cannot find the byte downloaded :( sigh just the number, however is a stream so the endEvent will never be raised.I was thinking to change the behaviour of WebClient...
BloopDev
That's exactly what I was doing - trying to hook to the DownloadProgressChanged vent but unfortunately it doesn't directly offer access to the stream. I can see that the number of received bytes is constantly growing so that's a good sign. I am trying to figure out a way to access that buffer.
Dennis Delimarsky
I think that the use of reflection can be a good point to start, should be somewhere the buffer of data read inside the WebClient object but i dunno if Microsoft would agree :)
BloopDev
I was just digging through WebClient using the .NET Reflector and I found a private class called DownloadBitsState - there is an internal byte array called InnerBuffer - now I only need to figure out a way to access it via reflection.
Dennis Delimarsky