其他分享
首页 > 其他分享> > 阿里云视频点播

阿里云视频点播

作者:互联网

 

 

依赖采用阿里官网版本  否则会报错

<dependencies>
    <dependency>
        <groupId>com.aliyun</groupId>
        <artifactId>aliyun-java-sdk-core</artifactId>
        <version>4.5.1</version>
    </dependency>
    <dependency>
        <groupId>com.aliyun.oss</groupId>
        <artifactId>aliyun-sdk-oss</artifactId>
        <version>3.10.2</version>
    </dependency>
    <dependency>
        <groupId>com.aliyun</groupId>
        <artifactId>aliyun-java-sdk-vod</artifactId>
        <version>2.15.11</version>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.28</version>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20170516</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.2</version>
    </dependency>
    <dependency>
        <groupId>com.aliyun.vod</groupId>
        <artifactId>upload</artifactId>
        <version>1.4.14</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/src/main/resources/aliyun-java-vod-upload-1.4.14.jar</systemPath>
    </dependency>

</dependencies>


    <repositories>
        <repository>
            <id>aliyun</id>
            <name>aliyun</name>
            <url>https://maven.aliyun.com/nexus/content/groups/public</url>
        </repository>
    </repositories>

 

https://help.aliyun.com/document_detail/106648.htm?spm=a2c4g.11186623.0.0.7d865d87taNHmj#multiTask2011

 

 获取视频地址

public class TestVod {
    public static void main(String[] args) {
        //根据视频id获取视频播放地址
        //创建初始化对象
        try {
                DefaultAcsClient client = initVodClient.initVodClient("LTAI5t9L2oZH6ZbKA6CtKM6u", "3ju3wxy7PeG4LaUgVqi1BEUcOy8PXQ");
            //创建获取视频地址request和response对象
            GetPlayInfoRequest request = new GetPlayInfoRequest();
            GetPlayInfoResponse response = new GetPlayInfoResponse();
            //向request对象里面设置 视频id
            request.setVideoId("0652e064d73f4938987f46a09442953f");
            //调用初始化对象里面的方法传递request  获取数据
            response = client.getAcsResponse(request);
            List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
            //播放地址
            for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
                System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");
            }
            //Base信息
            System.out.print("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
public class initVodClient {
    //填入AccessKey信息
    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;
    }
}

获取视频播放凭证

    public static void main(String[] args) {
       //根据视频id获取播放凭证
        //创建初始化对象
        try {
            DefaultAcsClient client = initVodClient.initVodClient("LTAI5t9L2oZH6ZbKA6CtKM6u", "3ju3wxy7PeG4LaUgVqi1BEUcOy8PXQ");
            //创建获取视频凭证的request和response对象
            GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
            GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();
            //向request设置视频的id值
            request.setVideoId("0652e064d73f4938987f46a09442953f");
            //调用初始化对象的方法获得凭证
            response = client.getAcsResponse(request);
            System.out.println("PlayAuth"+response.getPlayAuth());
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }

 

 

 

mvn install:install-file -DgroupId=com.aliyun.vod -DartifactId=upload -Dversion=1.4.12 -Dpackaging=jar -Dfile=aliyun-java-vod-upload-1.4.12.jar

 

https://help.aliyun.com/document_detail/53406.html

 

标签:视频,request,阿里,initVodClient,aliyun,视频点播,com,response
来源: https://www.cnblogs.com/Lcch/p/16527027.html