整合阿里雲視頻播放器


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;
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM