【问题标题】:Streaming video from Azure blob storage从 Azure Blob 存储流式传输视频
【发布时间】:2013-11-08 11:15:35
【问题描述】:

我无法将存储在 Azure blob 存储中的 .mp4 视频显示在 Azure 上托管的网站上。视频类型设置为video/mp4,存储账户不公开,但链接到web角色,我用这段代码更新了版本:

var credentials = new StorageCredentials("myaccountname", "mysecretkey"); 
var account = new CloudStorageAccount(credentials, true); 
var client = account.CreateCloudBlobClient(); 
var properties = client.GetServiceProperties(); 
properties.DefaultServiceVersion = "2012-02-12"; 
client.SetServiceProperties(properties); 

我没有使用任何视频播放器,只是 HTML5 视频标签。我也不需要任何花哨的东西,我只想播放视频。

查看 Chrome 开发工具中的网络选项卡,GET 请求有两个条目来获取视频。第一个状态为(pending),下一个状态为(canceled)

我还给了它一个指向网站内容文件夹中的视频的链接。这个也以pending 开头,但以204 Partial Content 解析,视频播放正常。

我没有东西可看,感谢任何帮助和指点。

【问题讨论】:

  • 您包含视频文件的容器是私有的吗?你能解释一下为什么要执行上面的代码吗?该代码与视频流无关。
  • @GauravMantri 该容器是私有的,但我以某种方式期望它可以工作,因为存储帐户已链接到 webrole。将其设置为公开可以解决流媒体问题,但我不希望它公开。该代码与更新 API 有关,因此它允许在视频未完全加载的情况下跳过视频。

标签: video azure video-streaming azure-storage


【解决方案1】:

根据您上面的 cmets,您需要的是 Shared Access Signature。使用下面的代码在您的 mp4 文件上创建共享访问签名。

        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.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-26
    • 2019-01-27
    • 1970-01-01
    • 2019-12-04
    • 2012-04-14
    • 2019-12-29
    • 1970-01-01
    相关资源
    最近更新 更多