【问题标题】:Save .mp4 to Windows Phone video library将 .mp4 保存到 Windows Phone 视频库
【发布时间】:2014-09-27 21:03:14
【问题描述】:

我想知道如何从 URI 下载 MP4 视频文件并将其保存到 Windows Phone 8.1 上的媒体库中。 如果它可以在通用应用程序中工作,那就太好了 - 但不是必须的。

我发现此代码可将图像保存到相机胶卷 - 我是否使用 *.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);
            }
        }
    }
}

【问题讨论】:

    标签: c# download windows-phone-8.1 mp4 win-universal-app


    【解决方案1】:

    所以我终于想通了,这就是我的代码的样子:

    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();
    }
    

    【讨论】:

    • 您应该在 WMAppManifest.xml 中启用 ID_CAP_MEDIALIB_PHOTO 功能以访问“SavedPictures”相册。
    • 嗨,我在 windows phone 8.1 上试过这个,但无法下载视频。你能帮帮我吗..我有视频网址可以下载..
    猜你喜欢
    • 2020-09-24
    • 2015-01-06
    • 2014-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-21
    • 1970-01-01
    相关资源
    最近更新 更多