HttpWebRequest for ShoutCast on Windows Phone7

I am streaming a streamcastcast in my phone 7 app window

I run 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 CallBack-> RespCallBack is never called ...

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

I am tired and use WebClient which seems to be passing data,

the problem in this case is that it never causes the end of OpenReadCompleted due to the endelss shoutcast stream

thanks for the support

any help would be appreciated

+3
source share
4 answers

SHOUTcast , . DownloadStringAsync ( WebClient), PLS URL- RegEx.

URL-, , MediaStreamSource, MediaElement, .

MediaStreamSource .

+3

. ( throw, .)

    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();
    }
+1

, :

webRequest.AllowReadStreamBuffering = false;
0

Shoutcast MediaElement MediaStreamSource. , Shoutcast, MediaStreamSource - , . . mp3 ( mp3), MediaStreamSource. :

private void Button_Click(object sender, RoutedEventArgs e)
{
    var assembly = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();
    var res = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Demo1.sample.mp3");

    byte[] data = new byte[res.Length];
    res.Read(data, 0, data.Length);

    MemoryStream ms = new MemoryStream();
    ms.Write(data, 0, data.Length);
    ms.Position = 0;

    ShoutcastMediaStreamSource ss = new ShoutcastMediaStreamSource(ms);
    player.SetSource(ss);             
}

my ShoutcastMediaStreamSource MenagedMediaHelpers. , ShoutcastMediaStreamSource debbuger, , OpenMediaAsync() , GetSampleAsync() MediaElement, , , ! , , . , GetSampleAsync() , ( ) 30 , . 10 . , , ().

- Silverlight -!. . .

http://timheuer.com/blog/archive/2010/08/16/download-and-store-media-for-playback-in-windows-phone-7-using-mediastreamsource.aspx

and there is a comment:

If Mp3MediaStreamSource is set as the source for MediaElement, then MediaElement does not play this file and does not detect errors in Windows Phone 7 sdk RTM version. In the preface, it worked, but not work with the Windows 7 sdk phone final release.

0
source

Source: https://habr.com/ru/post/1765275/


All Articles