【发布时间】:2019-12-04 11:42:00
【问题描述】:
我已将视频文件上传到 Azur Blob(容器),我想通过 Streaming 在移动应用程序中访问它们。我有扩展名为 .mp4 的文件。我已经完成了从 blob 下载并存储在本地驱动器中的代码,然后使用默认播放器播放,但我想为用户提供流式传输而不是下载的选项。 这个方法我用过
var credentials = new StorageCredentials("myaccountname", "mysecretkey");
var account = new CloudStorageAccount(credentials, true);
var container = account.CreateCloudBlobClient().GetContainerReference("yourcontainername");
var blob = container.GetBlockBlobReference("yourmp4filename");
var sas = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
{
Permissions = SharedAccessBlobPermissions.Read,
SharedAccessExpiryTime = DateTime.UtcNow.AddHours(1),//Set this date/time according to your requirements
});
var urlToBePlayed = string.Format("{0}{1}", blob.Uri, sas);//This is the URI which should be embedded in your video player.
问题:- 如果我浏览 Url(Blob Url) ,它会下载文件而不是直接播放它。但是在 App 中,什么都没有出现。黑屏。 我正在使用
<WebView Source="{Binding VideoUrl}" HeightRequest="200" WidthRequest="200"/>
在虚拟机中:
VideoUrl=url;
【问题讨论】:
-
您能检查一下您的视频 blob 的 ContentType 吗?它会影响浏览器对其进行操作的行为。如果是默认值
application/octet-stream,应该是下载的,需要改成video/mp4。 -
@ZhaoxingLu-Microsoft,感谢您的回复。我试过 this 。似乎 ListBlob 不可用,对于 ListBlobsSegmentedAsync ,我找不到一个。我希望我能找到一个使用 ListBlobsSegmentedAsync 的。你能帮忙吗?
-
这是您需要的吗? stackoverflow.com/a/54934260/2995449
-
没有。我使用 ListBlobsSegmentedAsync 对其进行了转换。现在它也在浏览器和应用程序中播放。这就像解决一个难题并跳到另一个难题。谢谢@ZhaoxingLu-Microsoft :)
标签: azure xamarin.forms azure-blob-storage