本示例介绍使用Alibaba Cloud SDK for Java调用GetPlayInfo接口获取视频播放地址。

前提条件

在调用GetPlayInfo接口前,确保:
  • 已经开通了视频点播服务。
  • 已完成域名绑定,详情参见域名管理
  • 已上传一个视频并获取到该视频的视频ID(videoId)。
  • 安装视频点播Java SDK,详情参见安装SDK

示例代码

package com.ygx.program;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse;
import com.google.gson.Gson;

public class TestGetPlayInfo {

    public static void main(String[] args) {
        // 创建SubmitMediaInfoJob实例并初始化
        DefaultProfile profile = DefaultProfile.getProfile(
                "cn-Shanghai",                // // 点播服务所在的地域ID,中国大陆地域请填cn-shanghai
                "<your-access-key-id>",        // 您的AccessKey ID
                "<your-access-key-secret>" );    // 您的AccessKey Secret
        IAcsClient client = new DefaultAcsClient(profile);
        GetPlayInfoRequest request = new GetPlayInfoRequest();
        // 视频ID。
        request.setVideoId("<your-video-id>");
        try {
            GetPlayInfoResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
            for (GetPlayInfoResponse.PlayInfo playInfo : response.getPlayInfoList()) {
                // 播放地址
                 System.out.println("PlayInfo.PlayURL = " + playInfo.getPlayURL());
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }
    }
}
说明 更多媒体处理服务接口内容,请参见API概览