通过Xamarin将视频上传到Azure存储

编程入门 行业动态 更新时间:2024-10-26 15:21:13
本文介绍了通过Xamarin将视频上传到Azure存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将视频文件上传到我的Azure存储帐户.我已经将其与图像配合使用,但是尝试查看上传的视频会显示消息不支持视频格式或MIME类型".视频格式为mp4.

我使用以下代码进行上传:

public async Task UploadVideo(Stream video, string path) { var container = GetContainer("videos"); // Creates the container if it does not exist await CreateContainer(container); //Gets the file extension string lastPart = path.Split('.').Last(); // Uploads the video to the blob storage CloudBlockBlob videoBlob = container.GetBlockBlobReference(path); videoBlob.Properties.ContentType = "video/" + lastPart; await videoBlob.UploadFromStreamAsync(video); }

我做错什么了吗?

谢谢

这是我用来在手机上捕获视频的代码:

private async Task TakeVideoButton_Clicked(object sender, EventArgs e) { if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakeVideoSupported) { await DisplayAlert("No Camera", ":( No camera avaialble.", "OK"); return; } mediaFile = await CrossMedia.Current.TakeVideoAsync(new Plugin.Media.Abstractions.StoreVideoOptions { Name = "video.mp4", Directory = "DefaultVideos", }); if (mediaFile == null) return; await DisplayAlert("Video Recorded", "Location: " + mediaFile.Path, "OK"); videoStream = mediaFile.GetStream(); file.Dispose(); }

解决方案

我只是在手机上而不是在模拟器上测试了它,并且在那儿工作得很好,所以我将假定它纯粹是与模拟器有关的问题. >

I'm trying to upload a video file to my Azure Storage account. I've got it working with images, however trying to view an uploaded video gives the message "Video format or MIME-type is not supported". The video format is mp4.

I use the following code to upload:

public async Task UploadVideo(Stream video, string path) { var container = GetContainer("videos"); // Creates the container if it does not exist await CreateContainer(container); //Gets the file extension string lastPart = path.Split('.').Last(); // Uploads the video to the blob storage CloudBlockBlob videoBlob = container.GetBlockBlobReference(path); videoBlob.Properties.ContentType = "video/" + lastPart; await videoBlob.UploadFromStreamAsync(video); }

Am I doing something wrong?

Thanks

Edit:

Here's the code I use to capture video on the phone:

private async Task TakeVideoButton_Clicked(object sender, EventArgs e) { if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakeVideoSupported) { await DisplayAlert("No Camera", ":( No camera avaialble.", "OK"); return; } mediaFile = await CrossMedia.Current.TakeVideoAsync(new Plugin.Media.Abstractions.StoreVideoOptions { Name = "video.mp4", Directory = "DefaultVideos", }); if (mediaFile == null) return; await DisplayAlert("Video Recorded", "Location: " + mediaFile.Path, "OK"); videoStream = mediaFile.GetStream(); file.Dispose(); }

解决方案

I just tested this on my phone instead of my emulator and it worked perfectly there, so I'm going to assume it's purely a emulator related issue.

更多推荐

通过Xamarin将视频上传到Azure存储

本文发布于:2023-11-17 07:39:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609330.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视频   Xamarin   Azure

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!