All Products
Search
Document Center

ApsaraVideo Live:Use APIs to implement a production studio in playlist mode

Last Updated:Dec 11, 2025

This topic describes how to call API operations to use a production studio in playlist mode for live streaming. A production studio in playlist mode enables you to quickly aggregate multiple videos for live streaming across various content types and scenarios. This lets you start live streaming at scheduled times, provides more diverse content, and improves user stability. Commercials can be automatically inserted in real time or at scheduled times to help increase revenue.

Overview

image

You can follow these steps to use a production studio in playlist mode for live streaming:

  1. Enable the video-on-demand (VOD) bucket: After activating ApsaraVideo VOD, you are assigned an independent VOD bucket in each region. You must enable the bucket before uploading and managing media resources in a region. No additional configurations are required.

  2. Upload videos: Upload videos to the VOD bucket in the sequence they should be played.

  3. Add a streaming domain: The streaming domain provides the streaming URL for live streams. Viewers can watch live streams using this URL.

  4. Call an API operation to configure a production studio in playlist mode: You can call an API operation to specify how many times each video plays and how many times the episode list repeats. For example, video A plays once, B plays twice, and C plays three times. After completing these steps, query the playback information about the episode list and start playback.

Prerequisites

  • An Alibaba Cloud account is created and has passed real-name verification.

  • Activate ApsaraVideo VOD, ApsaraVideo Live, and the Cloud Production Studio service. For more information, see Activate ApsaraVideo VOD, Activate ApsaraVideo Live and purchase resource plans, and Activate the Cloud Production Studio service.

    Note

    The production studio feature is currently supported only in the China (Shanghai), China (Beijing), Singapore, and Indonesia (Jakarta) regions, with support for more regions coming soon.

  • You have prepared a streaming domain. For a quick start, we recommend that you set the live center to a region outside mainland China and the acceleration region to Outside Chinese Mainland. This way, you do not need to apply for an Internet Content Provider (ICP) filing for the streaming domain.

  • The AliyunFCFullAccess, AliyunLiveFullAccess, and AliyunVODFullAccess policies are attached to a Resource Access Management (RAM) user. For more information, see Create and grant permissions to a RAM user.

Step 1: Enable the VOD bucket

In the ApsaraVideo VOD console, choose Configuration Management > Media Management Configuration > Storage and click Enable VOD buckets for the VOD system bucket.

Note

Wait until the bucket is enabled. You can use the bucket only after the system displays a Bucket Enabled Successfully message and the bucket status is Normal.

image

Step 2: Upload videos

  1. On the Media Files > Audio/Video page in the ApsaraVideo VOD console, you can click Upload.

  2. On the Upload Media page, click Add Media.

    image

  3. In the Add Media dialog box, select Local Upload, select the three prepared video files from your local device, and click Upload.

    image

  4. After the upload is successful, view and record the resource ID on the Audio/Video page. Then, in the Actions column, click More > Make Available on Cloud Studio to make the content available for real-time display in the production studio of ApsaraVideo Live. For information about the features of a production studio, see Introduction to Functional Areas.

    image

Step 3: Add a streaming domain

  1. In the ApsaraVideo Live console, go to the Domain Names page and click Add Domain Name.

  2. Configure the domain name as needed. Click Next. For more information about the parameters, see Add an accelerated domain name.

    image

  3. Record the generated CNAME for subsequent use.

    image

  4. On the Alibaba Cloud DNS - Public Authoritative Resolution page, find the domain name you want to configure and click Settings in the Actions column.

  5. Click Add Record, complete the CNAME configuration, and click Confirm. For more information, see Configure CNAME resolution for a domain name.

    image

Step 4: Call an API operation to configure a production studio in playlist mode

  1. Open Intellij IDEA and create a Maven project. In the pom.xml file, create a <dependencies></dependencies> tag and add the following dependencies:

     <dependency>
        <groupId>com.aliyun</groupId>
        <artifactId>live20161101</artifactId>
        <version>2.0.0</version>
     </dependency>
     <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.76</version>
     </dependency>
    
  2. In the src/main/java directory, right-click `java` and create a Java class. In this example, name the Java class bodan.

  3. Configure the following parameters and run the sample code.

    package com.alibaba.aliyundebug.common;
    
    import com.alibaba.fastjson.JSON;
    import com.alibaba.fastjson.JSONArray;
    import com.alibaba.fastjson.JSONObject;
    import com.aliyun.live20161101.Client;
    import com.aliyun.live20161101.models.*;
    import com.aliyun.teaopenapi.models.Config;
    import org.apache.commons.codec.digest.DigestUtils;
    
    import java.util.List;
    import java.util.Random;
    import java.util.UUID;
    
    public class Bodan {
        private final static String ACCESS_KEY_ID = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        private final static String ACCESS_KEY_SECRET = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
    
        private static class LiveClient {
            private static volatile Client instance;
    
            private LiveClient() {
            }
    
            public static Client getInstance(String endpoint, String accessKeyId, String accessKeySecret) {
                if (instance == null) {
                    synchronized (LiveClient.class) {
                        if (instance == null) {
                            try {
                                Config config = new Config();
                                config.setEndpoint(endpoint);
                                config.setAccessKeyId(accessKeyId);
                                config.setAccessKeySecret(accessKeySecret);
                                instance = new Client(config);
                            } catch (Exception e) {
                                throw new RuntimeException("Live client initialization failed: " + e.getMessage(), e);
                            }
                        }
                    }
                }
                return instance;
            }
        }
    
        private static CreateCasterResponse createCaster(Client client) throws Exception {
            CreateCasterRequest request = new CreateCasterRequest();
    
            Random random = new Random();
            int i = random.nextInt(100000);
            request.setCasterName("casterName" + i);
    
            UUID uuid = UUID.randomUUID();
            String token = "thisIsaToken";
            String clientToken = DigestUtils.sha256Hex(token + uuid);
            request.setClientToken(clientToken);
    
            // To use an episode list, you only need to create a production studio in playlist mode.
            request.setNormType(6);
            request.setChargeType("PostPaid");
    
            CreateCasterResponse response = client.createCaster(request);
    
            System.out.println("The production studio is created. Response: " + JSON.toJSONString(response));
            return response;
        }
    
        private static void setCasterConfig(Client client, String casterId,String domainName) throws Exception {
            SetCasterConfigRequest request = new SetCasterConfigRequest();
            request.setCasterId(casterId);
    
            // Configure the domain name.
            request.setDomainName(domainName);
            JSONObject transcodeConfig = new JSONObject();
            JSONArray liveTemplate = new JSONArray();
            //Configure a template for the production studio.
            liveTemplate.add("lld");
            transcodeConfig.put("LiveTemplate", liveTemplate);
            //Configure a transcoding template.
            transcodeConfig.put("CasterTemplate", "lp_sd");
            request.setTranscodeConfig(transcodeConfig.toJSONString());
    
            SetCasterConfigResponse response = client.setCasterConfig(request);
            System.out.println("The production studio is configured. Response: " + JSON.toJSONString(response));
        }
    
        private static StartCasterResponse startCaster(Client client, String casterId) throws Exception {
            StartCasterRequest startCasterRequest = new StartCasterRequest();
            startCasterRequest.setCasterId(casterId);
            StartCasterResponse acsResponse = client.startCaster(startCasterRequest);
            System.out.println("The production studio is started.");
            return acsResponse;
        }
    
        private static StopCasterResponse stopCaster(Client client, String casterId) throws Exception {
            StopCasterRequest stopCasterRequest = new StopCasterRequest();
            stopCasterRequest.setCasterId(casterId);
            StopCasterResponse acsResponse = client.stopCaster(stopCasterRequest);
            System.out.println("The production studio is stopped.");
            return acsResponse;
        }
    
        private static AddShowIntoShowListResponse addShowIntoShowList(Client client, String showName, String resourceId, String resourceUrl,
                                                                       String resourceType, Integer spot, Integer repeatTimes,
                                                                       String casterId, Long duration) throws Exception {
            AddShowIntoShowListRequest addShowIntoShowListRequest = new AddShowIntoShowListRequest();
    
            if (casterId == null || resourceType == null) {
                return null;
            }
            if (resourceId == null && resourceUrl == null) {
                return null;
            }
            addShowIntoShowListRequest.setCasterId(casterId);
            addShowIntoShowListRequest.setResourceType(resourceType);
            if (showName != null) {
                addShowIntoShowListRequest.setShowName(showName);
            }
            if (resourceUrl != null) {
                addShowIntoShowListRequest.setResourceUrl(resourceUrl);
            }
            if (resourceId != null) {
                addShowIntoShowListRequest.setResourceId(resourceId);
            }
            if (spot != null) {
                addShowIntoShowListRequest.setSpot(spot);
            }
            if (repeatTimes != null) {
                addShowIntoShowListRequest.setRepeatTimes(repeatTimes);
            }
            if (duration != null) {
                addShowIntoShowListRequest.setDuration(duration);
            }
            return client.addShowIntoShowList(addShowIntoShowListRequest);
        }
    
        private static void removeShowFromShowList(Client client, String casterId, String showId) throws Exception {
            RemoveShowFromShowListRequest removeShowFromShowList = new RemoveShowFromShowListRequest();
            removeShowFromShowList.setShowId(showId);
            removeShowFromShowList.setCasterId(casterId);
            RemoveShowFromShowListResponse removeShowFromShowListFromShowListResponse = client.removeShowFromShowList(removeShowFromShowList);
            System.out.println("removeShowFromShowListFromShowListResponse:" + JSON.toJSONString(removeShowFromShowListFromShowListResponse));
        }
    
        private static void modifyShowList(Client client, String casterId, String showId, Integer repeatTimes, Integer spot,
                                                             String highPriorityShowId, String highPriorityShowStartTime) throws Exception {
            ModifyShowListRequest modifyShowListRequest = new ModifyShowListRequest();
            if (casterId != null) {
                modifyShowListRequest.setCasterId(casterId);
            }
            if (showId != null) {
                modifyShowListRequest.setShowId(showId);
            }
            if (repeatTimes != null) {
                modifyShowListRequest.setRepeatTimes(repeatTimes);
            }
            if (spot != null) {
                modifyShowListRequest.setSpot(spot);
            }
            if (highPriorityShowId != null) {
                modifyShowListRequest.setHighPriorityShowId(highPriorityShowId);
            }
            if (highPriorityShowStartTime != null) {
                modifyShowListRequest.setHighPriorityShowStartTime(highPriorityShowStartTime);
            }
            ModifyShowListResponse modifyShowListResponse = client.modifyShowList(modifyShowListRequest);
            System.out.println("The episode list is modified. Response: " + JSON.toJSONString(modifyShowListResponse));
        }
    
        private static void describeShowList(Client client, String casterId) throws Exception {
            DescribeShowListRequest describeShowListRequest = new DescribeShowListRequest();
            if (casterId != null) {
                describeShowListRequest.setCasterId(casterId);
            }
            DescribeShowListResponse describeShowListRequestResponse = client.describeShowList(describeShowListRequest);
            System.out.println("Query of the episode list is complete. Response parameters:" + JSON.toJSONString(describeShowListRequestResponse));
    
            DescribeShowListResponseBody showListBody = describeShowListRequestResponse.getBody();
            JSONObject showList = JSON.parseObject(showListBody.getShowList());
            JSONArray shows = showList.getJSONArray("Shows");
            //Display the episode list information.
            for (int i = 0; i < shows.size(); i++) {
                JSONObject show = (JSONObject) shows.get(i);
                String showId = show.getString("ShowId");
                String resourceType = show.getString("ResourceType");
                String resourceInfo = show.getString("ResourceInfo");
                Integer repeatTimes = show.getInteger("RepeatTimes");
                Long duration = show.getLong("Duration");
                String showInfo = String.format("show%d: showId: %s \n resourceType: %s  \n  resourceInfo: %s \n RepeatTimes: %d \n Duration: %d",
                        i + 1, showId, resourceType, resourceInfo, repeatTimes, duration);
                System.out.println(showInfo);
            }
        }
    
        private static void playChoosenShow(Client client, String casterId, String showId) throws Exception {
            PlayChoosenShowRequest playChoosenShow = new PlayChoosenShowRequest();
            playChoosenShow.setCasterId(casterId);
            playChoosenShow.setShowId(showId);
            PlayChoosenShowResponse playChoosenShowResponse = client.playChoosenShow(playChoosenShow);
            System.out.println("Successfully switched to showId: " + showId + ".");
        }
    
        private static List<DescribeCasterStreamUrlResponseBody.DescribeCasterStreamUrlResponseBodyCasterStreamsCasterStream> describeCasterStreamUrl(Client client, String casterId) throws Exception {
            DescribeCasterStreamUrlRequest describeCasterStreamUrlRequest = new DescribeCasterStreamUrlRequest();
            describeCasterStreamUrlRequest.setCasterId(casterId);
            DescribeCasterStreamUrlResponse response = client.describeCasterStreamUrl(describeCasterStreamUrlRequest);
            return response.getBody().getCasterStreams().getCasterStream();
        }
    
    
        public static void main(String[] args) throws Exception {
            Client client = LiveClient.getInstance("live.aliyuncs.com", ACCESS_KEY_ID, ACCESS_KEY_SECRET);
            // Create a production studio.
            CreateCasterResponse caster = createCaster(client);
            String casterId = caster.getBody().getCasterId();
            // Configure the production studio.
            String domainName = "example.aliyundoc.com"; // Set the domain name.
            setCasterConfig(client, casterId,domainName);
    
            // Add the three VOD files to the episode list in sequence. Play the first VOD file once, the second VOD file twice, and the third VOD file three times.
            String[] resourceIds = new String[]{"698d2b23581f476ea71107703e64****", "9c97e83e211a435b9f797e4e20ee****", "76c6addaa41c438985666a8a964f****"};
            for (int i = 0; i < resourceIds.length; i++) {
                String showName = "ShowName#" + i;
                Integer repeatTimes = i;
                addShowIntoShowList(client, showName, resourceIds[i], null, "vod", null, repeatTimes, casterId, null);
            }
            modifyShowList(client, casterId, null, 10, null, null, null);
            describeShowList(client, casterId);
            startCaster(client, casterId);
    
            Thread.sleep(500000);
    
            stopCaster(client, casterId);
        }
    
    }
    

    Parameter description:

    Parameter configuration information

    Description

    private final static String ACCESS_KEY_ID = "AccessKey ID";
    private final static String ACCESS_KEY_SECRET = "AccessKey Secret";

    You must use an AccessKey pair to complete identity verification. An AccessKey pair consists of an AccessKey ID and an AccessKey secret.

    • The AccessKey ID is used to verify the identity of a user.

    • The AccessKey secret is used to authenticate the key of a user. You must keep your AccessKey secret confidential.

    For more information, see Create an AccessKey pair.

    request.setDomainName("example.aliyundoc.com");

    The streaming domain.

    String[] resourceIds = new String[]{"698d2b23581f476ea71107703e64****", "9c97e83e211a435b9f797e4e20ee****", "76c6addaa41c438985666a8a964f****"};

    The resource ID. For more information, see 2. Upload videos.

  4. View the result.

    image

  5. On the Production Studios page, find the production studio that you created and click Enter in the Actions column. The three video-on-demand files are added to the playlist sequentially and played according to the specified configuration.

    image

    image

What to do next

To play the stream, click Streaming URL in the production studio to copy the URL. You can then use VLC media player, a live streaming demo, or a player SDK for playback. For more information, see Live Stream Playback.

image