我试图从视频网址下载视频文件。已创建视频文件,但此处不会进行下载。只生成57KB文件。我的代码在这里。
public async void DownloadTrack(Uri SongUri, string fileName)
{
using (HttpClient httpClient = new HttpClient())
{
var data = await httpClient.GetByteArrayAsync(SongUri);
StorageFolder storageFolder = KnownFolders.VideosLibrary;
var file = await storageFolder.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName);
///////////////////
using (var targetStream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
await targetStream.AsStreamForWrite().WriteAsync(data, 0, data.Length);
await targetStream.FlushAsync();
}
}
}
此处视频文件创建但不下载文件。我想下载文件。我搜索了很多这个。这里接受Stackoverflow的答案链接,但这也是一样的。 Example
你能提供更好的解决方案吗?