视频点播
作者:朱尚 / 日期:2020-12-11 / 分类:阿里云API接口 / 浏览:2214

阿里云视频点播接口文档开发:https://help.aliyun.com/document_detail/51236.htm

目前截止,暂没有dotNet的整体SDK可用,只能使用服务端的.Net SDK通过服务端获取视频上传凭证和地址,接着用JavaScript上传SDK通过获取到的上传凭证和地址进行操作。


JavaScript:SDK获取 https://help.aliyun.com/document_detail/52204.html?spm=a2c4g.11186623.6.1014.4fdc8d6elAMR9h

var uploader = new AliyunUpload.Vod({       
       userId:"122",       //阿里账号ID,必须有值
       partSize: 1048576,     //分片大小默认1 MB,不能小于100 KB
       parallel: 5,     //并行上传分片个数,默认5
     retryCount: 3,     //网络原因失败时,重新上传次数,默认为3
     retryDuration: 2,     //网络原因失败时,重新上传间隔时间,默认为2秒
     enableUploadProgress: true,      //是否上报上传日志到视频点播,默认为true
      'onUploadstarted': function (uploadInfo) { //开始上传
        log("onUploadStarted:" + uploadInfo.file.name + ", endpoint:" + uploadInfo.endpoint + ", bucket:" + uploadInfo.bucket + ", object:" + uploadInfo.object);    //上传方式1,需要根据uploadInfo.videoId是否有值,调用视频点播的不同接口获取uploadauth和uploadAddress,如果videoId有值,调用刷新视频上传凭证接口,否则调用创建视频上传凭证接口
    if (uploadInfo.videoId) {            //如果uploadInfo.videoId存在,调用刷新视频上传凭证接口
         }     else{            //如果uploadInfo.videoId不存在,调用获取视频上传地址和凭证接口
      //从视频点播服务获取的uploadAuth、uploadAddress和videoId,设置到SDK里
         uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress,videoId);
      },      //文件上传成功
      'onUploadSucceed': function (uploadInfo) {
        log("onUploadSucceed: " + uploadInfo.file.name + ", endpoint:" + uploadInfo.endpoint + ", bucket:" + uploadInfo.bucket + ", object:" + uploadInfo.object);
      },      //文件上传失败
      'onUploadFailed': function (uploadInfo, code, message) {
        log("onUploadFailed: file:" + uploadInfo.file.name + ",code:" + code + ", message:" + message);
      },      //文件上传进度,单位:字节
      'onUploadProgress': function (uploadInfo, totalSize, loadedPercent) {
          log("onUploadProgress:file:" + uploadInfo.file.name + ", fileSize:" + totalSize + ", percent:" + Math.ceil(loadedPercent * 100) + "%");
      },      //上传凭证超时
      'onUploadTokenExpired': function (uploadInfo) {          console.log("onUploadTokenExpired");      //实现时,根据uploadInfo.videoId调用刷新视频上传凭证接口重新获取UploadAuth
      //从点播服务刷新的uploadAuth,设置到SDK里

      uploader.resumeUploadWithAuth(uploadAuth);
      },    //全部文件上传结束
    'onUploadEnd':function(uploadInfo){           console.log("onUploadEnd: uploaded all the files");
       }
});

.Net SDK获取 

    //阿里云视频点播初始化
    public static DefaultAcsClient InitVodClient(string accessKeyId, string accessKeySecret)
    {
        // 点播服务接入区域
        string regionId = "cn-shanghai";
        IClientProfile profile = DefaultProfile.GetProfile(regionId, accessKeyId, accessKeySecret); ;
        // DefaultProfile.AddEndpoint(regionId, regionId, "vod", "vod." + regionId + ".aliyuncs.com");
        return new DefaultAcsClient(profile);
    }
    //获取视频上传地址和凭证
    public static string CreateUploadVideo(string title, string filename)
    {
        try
        {
            // 构造请求
            CreateUploadVideoRequest request = new CreateUploadVideoRequest();
            request.Title = title;
            request.FileName = filename;
            // request.Tags = "tags1,tags2";
            // request.Description = "this is a sample description";
            // request.CoverURL = "http://cover.sample.com/sample.jpg";
            // request.CateId = -1;
            // request.TemplateGroupId = "278840921dee4963bb5862b43aeb2273";
            // 初始化客户端
            DefaultAcsClient client = InitVodClient("Your accessKeyId", "Your accessKeySecret");
            // 发起请求,并得到响应结果
            CreateUploadVideoResponse response = client.GetAcsResponse(request);

            //string repVId = response.VideoId;
            string Rep = response.UploadAuth + "|" + response.UploadAddress + "|" + response.VideoId;

            return Rep;
            //Console.WriteLine("RequestId = " + response.RequestId);
            //Console.WriteLine("UploadAddress = " + response.UploadAddress);
            //Console.WriteLine("UploadAuth = " + response.UploadAuth);
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
    }
    //刷新视频上传凭证
    public static string RefreshUploadVideo(string VideoId)
    {
        try
        {
            // 构造请求
            RefreshUploadVideoRequest request = new RefreshUploadVideoRequest();
            request.VideoId = VideoId;
            // 初始化客户端
            DefaultAcsClient client = InitVodClient("Your accessKeyId", "Your accessKeySecret");
            // 发起请求,并得到 response
            RefreshUploadVideoResponse response = client.GetAcsResponse(request);

            string repVId = response.VideoId;

            return RefreshUploadVideo(repVId);
        }
        catch (ServerException ex)
        {
            return ex.ToString();
        }
        catch (ClientException ex)
        {
            return ex.ToString();
        }
    }


上一篇:没有了
下一篇:对象存储OSS
本文标签: aliyun VoD
本文链接:http://www.banzhuan.net/detail/361