使用MediaElement播放视频并下载

时间:2013-02-04 09:25:36

标签: c# .net windows-phone-7

我想在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);
        }
    }

0 个答案:

没有答案