All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zopen.aliyun.vod.service.AliyunVodPlayService Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
package com.zopen.aliyun.vod.service;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import com.zopen.aliyun.exception.AliyunAssert;
import com.zopen.aliyun.exception.AliyunException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component("atoAliyunVodPlayService")
public class AliyunVodPlayService {

    private static final Logger logger = LoggerFactory.getLogger(AliyunVodPlayService.class);

    @Autowired
    private DefaultAcsClient client;

    /**
     * 获取视频播放凭证
     *
     * @param videoId 视频ID
     * @return PlayAuth
     */
    public String getVideoPlayAuth(String videoId) {
        GetVideoPlayAuthResponse response = getVideoPlayAuthAndVideoMeta(videoId);
        return response.getPlayAuth();
    }

    /**
     * 获取视频播放凭证和视频信息
     *
     * @param videoId 视频ID
     * @return GetVideoPlayAuthResponse
     */
    public GetVideoPlayAuthResponse getVideoPlayAuthAndVideoMeta(String videoId) {
        AliyunAssert.notNullAndEmpty(videoId, "videoId 不能为空");
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        request.setVideoId(videoId);
        try {
            logger.debug(">>发起获取阿里云视频播放凭证请求:videoId[{}]", videoId);
            GetVideoPlayAuthResponse response = client.getAcsResponse(request);
            logger.debug("<<获取阿里云视频播放凭证成功:playAuth[{}]", response.getPlayAuth());
            return response;
        } catch (Exception e) {
            logger.error("<<获取阿里云视频播放凭证失败:" + e.getMessage(), e);
            throw new AliyunException("获取视频播放凭证失败:" + e.getMessage());
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy