将.mp4保存到Windows Phone视频库
问题描述:
我想知道如何从URI下载MP4视频文件并将其保存到Windows Phone 8.1上的媒体库中。 如果它在通用应用程序中工作会很好 - 但它不一定。将.mp4保存到Windows Phone视频库
我发现这段代码将图像保存到相机胶卷上 - 我是否用同样的方式将它保存到视频库中?* .mp4?我是否可以将一个下载流(不确定这是否合理)传递给该功能?
StorageFolder testFolder = await StorageFolder.GetFolderFromPathAsync(@"C:\test");
StorageFile sourceFile = await testFolder.GetFileAsync("TestImage.jpg");
StorageFile destinationFile = await KnownFolders.CameraRoll.CreateFileAsync("MyTestImage.jpg");
using (var sourceStream = await sourceFile.OpenReadAsync())
{
using (var sourceInputStream = sourceStream.GetInputStreamAt(0))
{
using (var destinationStream = await destinationFile.OpenAsync(FileAccessMode.ReadWrite))
{
using (var destinationOutputStream = destinationStream.GetOutputStreamAt(0))
{
await RandomAccessStream.CopyAndCloseAsync(sourceInputStream, destinationStream);
}
}
}
}
答
所以,我终于想通了,这是我的代码如下所示:
var httpClient = new HttpClient();
var response = await httpClient.GetAsync(url);
if (response.IsSuccessStatusCode)
{
var file = await response.Content.ReadAsByteArrayAsync();
StorageFile destinationFile
= await KnownFolders.SavedPictures.CreateFileAsync("file.mp4",
CreationCollisionOption.ReplaceExisting);
Windows.Storage.Streams.IRandomAccessStream stream = await destinationFile.OpenAsync(FileAccessMode.ReadWrite);
IOutputStream output = stream.GetOutputStreamAt(0);
DataWriter writer = new DataWriter(output);
writer.WriteBytes(file);
await writer.StoreAsync();
await output.FlushAsync();
}
您应该启用** ** ID_CAP_MEDIALIB_PHOTO能力,** ** WMAppManifest.xml访问“** SavedPictures **“相册。 – 2015-06-16 12:24:20
嗨,我试过这个Windows Phone 8.1,但无法下载视频。你可以请帮助我..我有视频网址下载.. – Arsal 2016-04-26 16:57:24
嗨,你可以请更新为什么这不起作用 – 2016-05-13 07:50:55