1

我想在 MediaElement 中播放来自网络的视频,同时也下载视频。

我尝试将 Stream 设置为源,但它不起作用。有可能做到吗?


编辑:

这就是我现在要做的,问题是我想从头开始播放,而不是在我完成下载文件时:

    public void StartDownloadFile(string aVideoUrl,string aId)
    {
        this.VideoUrl = aVideoUrl;
        this.id = aId;

        startPlaying = false;

        WebClient webClient = new WebClient();
        webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged);
        webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
        webClient.OpenReadAsync(new Uri(this.VideoUrl));
    }

    void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        try
        {
            if (e.Result != null)
            {

                #region Isolated Storage Copy Code
                isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication();

                bool checkQuotaIncrease = this.IncreaseIsolatedStorageSpace(e.Result.Length);

                string VideoFile = "VideoCache\\" + this.id + ".wmv";
                isolatedStorageFileStream = new IsolatedStorageFileStream(VideoFile, FileMode.Create, isolatedStorageFile);
                long VideoFileLength = (long)e.Result.Length;
                byte[] byteImage = new byte[VideoFileLength];
                e.Result.Read(byteImage, 0, byteImage.Length);
                isolatedStorageFileStream.Write(byteImage, 0, byteImage.Length);

                #endregion

                callbackFinish();

            }
        }
        catch (Exception ex)
        {
            //MessageBox.Show(ex.Message);
        }
    }

    void webClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {
        try
        {
            callbackDidUpdate((double)e.ProgressPercentage);

        }
        catch (Exception ex)
        {
            //MessageBox.Show(ex.Message);
        }
    }
4

0 回答 0