C# 使用MediaElement播放视频并下载
我想在MediaElement中播放网络视频,同时下载视频 我尝试将Stream设置为源代码,但它不起作用。有可能吗 编辑: 这就是我现在要做的,问题是我想从一开始就开始播放,而不是在下载完文件后:C# 使用MediaElement播放视频并下载,c#,.net,windows-phone-7,C#,.net,Windows Phone 7,我想在MediaElement中播放网络视频,同时下载视频 我尝试将Stream设置为源代码,但它不起作用。有可能吗 编辑: 这就是我现在要做的,问题是我想从一开始就开始播放,而不是在下载完文件后: public void StartDownloadFile(string aVideoUrl,string aId) { this.VideoUrl = aVideoUrl; this.id = aId; startPlaying =
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);
}
}
请显示您当前拥有的代码,以便我们提出改进建议。另外,请解释“不起作用”,例外情况?哪种类型?哪一行代码?我用code@MTA恐怕现在还不可能。如果您查看这篇文章,您会看到一条备注:对于已经有媒体作为流可用的情况,请使用此方法,而不是将源设置为URI。我也曾问过这样的问题,但找不到通过MediaElement实现的方法。