zoukankan      html  css  js  c++  java
  • 整合阿里云视频播放器

    1.创建接口,根据视频id获取视频播放凭证

       //根据视频id获取视频播放凭证
        @GetMapping("/getPlayAuth/{id}")
        public  R getPlayAuth(@PathVariable String id){
           try{
               //创建初始化对象
               DefaultAcsClient client = InitVodCilent.initVodClient(ConstantVodUtils.ACCESS_KEY_ID, ConstantVodUtils.ACCESS_KEY_SECRET);
               //创建获取播放凭证的request和response对象
               GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
               //向request中设置视频id
               request.setVideoId(id);
               //调用方法得到播放凭证
               GetVideoPlayAuthResponse response = client.getAcsResponse(request);
               String playAuth = response.getPlayAuth();
               return R.ok().data("playAuth",playAuth);
    
           }catch (Exception e){
               throw new GuliException(20001,"获取凭证失败");
           }
        }

    2.ConstantVodUtils工具类

    package com.atguigu.vod.Utils;
    
    import org.springframework.beans.factory.InitializingBean;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.stereotype.Component;
    
    @Component
    public class ConstantVodUtils implements InitializingBean {
    
        @Value("${aliyun.vod.file.keyid}")
        private String keyid;
    
        @Value("${aliyun.vod.file.keysecret}")
        private String keysecret;
    
        public static String ACCESS_KEY_SECRET;
        public static String ACCESS_KEY_ID;
    
        @Override
        public void afterPropertiesSet() throws Exception {
            ACCESS_KEY_ID = keyid;
            ACCESS_KEY_SECRET = keysecret;
        }
    }

    3.InitVodCilent

    package com.atguigu.vod.Utils;
    
    import com.aliyun.oss.ClientException;
    import com.aliyuncs.DefaultAcsClient;
    import com.aliyuncs.profile.DefaultProfile;
    
    public class InitVodCilent {
    
        public static DefaultAcsClient initVodClient(String accessKeyId, String accessKeySecret) throws ClientException {
            String regionId = "cn-shanghai";  // 点播服务接入区域
            DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
            DefaultAcsClient client = new DefaultAcsClient(profile);
            return client;
        }
    }
  • 相关阅读:
    移动前端不得不了解的Meta标签
    利用a标签自动解析URL
    看完让你彻底搞懂Websocket原理
    (十六)rk3399 android系统上电/dev/i2c-1权限不够
    (一)Android jni打印到logcat
    (二十五)防编译后函数名通过ida查看到
    (二十四)Ubuntu16.04配置ADB调试环境
    (十五)连接网络adb,android模拟器打开
    (十四)Android NDK混淆
    (二十三)ARM平台NEON指令的编译和优化
  • 原文地址:https://www.cnblogs.com/liqinzhen/p/14034698.html
Copyright © 2011-2022 走看看