本文介绍了通过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存储
发布评论