All Products
Search
Document Center

Audio and video playback

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see initVodClient.

Obtain the audio or video playback URL

For more information about the request and response parameters, see GetPlayInfo.

import com.aliyuncs.vod.model.v20170321.GetPlayInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse;

/*Method for obtaining the audio or video playback URL*/
public static GetPlayInfoResponse getPlayInfo(DefaultAcsClient client) throws Exception {
    GetPlayInfoRequest request = new GetPlayInfoRequest();
    request.setVideoId("Video ID");
    return client.getAcsResponse(request);
}

/*Call example*/
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    GetPlayInfoResponse response = new GetPlayInfoResponse();
    try {
        response = getPlayInfo(client);
        List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList(); 
        // The audio or video playback URL.
        for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
            System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");
        }
        // The basic information about the audio or video.
        System.out.print("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}

Obtain the video playback credential

For more information about the request and response parameters, see GetVideoPlayAuth.

import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;

/*Method for obtaining the video playback credential*/
public static GetVideoPlayAuthResponse getVideoPlayAuth(DefaultAcsClient client) throws Exception {
    GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
    request.setVideoId("Video ID");
    return client.getAcsResponse(request);
}

/*Call example*/
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();
    try {
        response = getVideoPlayAuth(client);
        // The video playback credential.
        System.out.print("PlayAuth = " + response.getPlayAuth() + "\n");
        // The video metadata.
        System.out.print("VideoMeta.Title = " + response.getVideoMeta().getTitle() + "\n");
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}