简体   繁体   English

WP7 音频流帮助

[英]WP7 Audio Streaming Help

So I've downloaded the samples from http://archive.msdn.microsoft.com/ManagedMediaHelpers .所以我从http://archive.msdn.microsoft.com/ManagedMediaHelpers下载了样本。

I've got my code working using MP3MediaStreamSource.我的代码使用 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.基本上,它试图告诉您在播放之前完全下载了 1 个文件。 It is not a good idea, since if the file is 10 MB, it may take a while before it completely downloads.这不是一个好主意,因为如果文件为 10 MB,则可能需要一段时间才能完全下载。

A better idea would be to chunk the file using Encoders, and read it in on need basis.一个更好的主意是使用编码器对文件进行分块,并根据需要读取它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM