开发者

WP7 Audio Streaming Help

So I've downloaded the samples from http://archive.msdn.microsoft.com/ManagedMediaHelpers.

I've got my code working using MP3MediaStreamSource. However, I don't fully understand the code would like some explanation.

public partial class MainPage : PhoneApplicationPage
{
    private static string mediaFileLocation = "http://file-here.mp3";
    private static HttpWebRequest request = null;
    private static Mp3MediaStreamSource mss = null;

    public MainPage()
    {
        InitializeComponent();
    }

    private void RequestCallback(IAsyncResult asyncResult)
    {
        HttpWebResponse response = request.EndGetResponse(asyncResult) as HttpWebResponse;
        Stream s = response.GetResponseStream();
        mss = new Mp3MediaStreamSource(s, response.ContentLength);
        Deployment.Current.Dispatcher.BeginInvoke(
            () =>
            {
                this.wp7AudioElement.Volume = 100;
                this.wp7AudioElement.SetSource(mss);
            });
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        request = WebRequest.CreateHttp(MainPage.mediaFileLocation);

        // NOTICE 
        // Makes this demo code easier but I wouldn't do this on a live phone as it will cause the whole 
        // file to download into memory at once.
        //
        // Instead, use the asynchronous methods and read the stream in the backgound and dispatch its
        // data as needed to the ReportGetSampleCompleted 开发者_高级运维call on the UIThread.
        request.AllowReadStreamBuffering = true;
        IAsyncResult result = request.BeginGetResponse(new AsyncCallback(this.RequestCallback), null);
    }
}

It's really just the last method I need explained, I don't understand the Notice as to why it's a bad idea and how to do it differently?


Basically, it is trying to tell you that you are downloading 1 file COMPLETELY before it plays. It is not a good idea, since if the file is 10 MB, it may take a while before it completely downloads.

A better idea would be to chunk the file using Encoders, and read it in on need basis.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜