All Products
Search
Document Center

:Have fun with long videos

Last Updated:May 10, 2023

Preface

Long videos, also known as online videos, are mainly in the form of pan-entertainment movies and TV plays. With the development of mobile devices and networks, users are having an increasingly personalized, specialized, and detailed demand for online videos in various fields, such as pan-entertainment, education, government and enterprise training, and convergence media. To this end, ApsaraVideo has launched an all-in-one solution that provides basic functions such as video playback and video management, as well as business functions such as real-time bullet comment sending and advertisement insertion. This topic describes the products required for a LongVideo application to help you quickly build a LongVideo application.

Client SDK

This section is intended for client developers.

The client SDK provides you with the capability to play videos.

Server configuration and development

This section is intended for server developers.

Before publishing produced videos online for users to watch and interact with, you need to configure and develop the following services:

  • ApsaraVideo VOD

ApsaraVideo VOD is an all-in-one audio- and video-on-demand solution. It integrates video collection, editing, and upload, media resource management, automatic transcoding (Narrowband HD™), video content moderation and analysis, and Content Delivery Network (CDN) for accelerated content delivery.

  • AppServer

To build a LongVideo application, you need to develop an AppServer that can provide the application with the following capabilities: registration, logon, storage of user relationship data as well as user and video relationship data, video lists, video upload signatures, and reception of ApsaraVideo VOD callback notifications. You can develop an AppServer on an Elastic Compute Service (ECS) instance.

When developing an AppServer, you need to authorize permissions to your Alibaba Cloud account. Each time you request to use ApsaraVideo VOD APIs or the client SDK, Alibaba Cloud verifies the user identity based on your requested operation to check whether your account has the necessary permissions. An AccessKey is required for user authentication. For more information about the server configuration and development, seeDownload source code andServer integration.

ApsaraVideo VOD

  1. Activate ApsaraVideo VOD.

  2. Learn about the product information on the product page of ApsaraVideo VOD on the Alibaba Cloud official website.

  3. Click Buy Now. On the subscription page that appears, select a billing method and confirm the order.

  4. After the service is activated, go to the Overview page of the ApsaraVideo VOD console and start using the service.

  5. Add a domain name.

  6. In the ApsaraVideo VOD console, choose CDN Configuration > Domain Names in the left-side navigation pane. On the Domain Names page that appears, add a domain name for video delivery and acceleration.

    Note

    Note: Ensure that the domain name is filed and you have the permission to use it.

  7. After the domain name is added, Alibaba Cloud CDN assigns you a CNAME address. Obtain the CNAME address and add the CNAME record.

    Note

    Note: Point the CNAME record to your domain name at your DNS service provider as prompted. For more information about how to configure a CNAME record on HiChina, Xinnet, or DNSPod, see Configure a CNAME. For more information about how to use ApsaraVideo VOD, see Get started with ApsaraVideo VOD.

AppServer

  • Configure the AccessKey of a Resource Access Management (RAM) user

    To use ApsaraVideo VOD APIs, you need to use an AccessKey for access to ApsaraVideo VOD. If you directly use an Alibaba Cloud account AccessKey, it may pose high security risks. In this case, you can use the AccessKey of a RAM user to effectively avoid security risks caused by the leakage of the AccessKey or password of your Alibaba Cloud account.

    When configuring permissions, select the AliyunVODFullAccess and AliyunSTSAssumeRoleAccess policies. The AliyunVODFullAccess policy provides you with access to ApsaraVideo VOD APIs, and the AliyunSTSAssumeRoleAccess policy allows you to use Security Token Service (STS) to obtain a temporary AccessKey, as shown in the following figure.

  • Configure an STS temporary AccessKey

    When a client submits a request to upload produced videos to the cloud, ApsaraVideo needs to deliver authentication information to the client. The previously mentioned RAM user AccessKey is permanently valid, but is not suitable to be delivered to and stored on the client. Therefore, ApsaraVideo needs to generate a temporarily valid AccessKey that can be used by the client. The procedure is as follows:

  1. Create a role.In the RAM console, choose RAM Roles > Create RAM Role. In the Create RAM Role dialog box that appears, follow instructions to create a RAM role.

  2. Configure role permissions.

    Note

    Note: Select the AliyunVODFullAccess policy as shown in the preceding figure.

  3. Use STS to obtain a temporary AccessKey.

    Write the following code on the AppServer:

    static AssumeRoleResponse assumeRole(String accessKeyId, String accessKeySecret,
                                  String roleArn, StringroleSessionName,     String policy,
                                  ProtocolType protocolType) throws ClientException {
       try {
         // Create an Alibaba Cloud AcsClient for initiating API requests.
         IClientProfile profile = DefaultProfile.getProfile(REGION_CN_HANGZHOU, accessKeyId, accessKeySecret);
         DefaultAcsClient client = new DefaultAcsClient(profile);
         // Create an AssumeRoleRequest and set request parameters.
         final AssumeRoleRequest request = new AssumeRoleRequest();
         request.setVersion(STS_API_VERSION);
         request.setMethod(MethodType.POST);
         request.setProtocol(protocolType);
         request.setRoleArn(roleArn);
         request.setRoleSessionName(roleSessionName);
         request.setPolicy(policy);
         // Initiate the request and obtain a response.
         final AssumeRoleResponse response = client.getAcsResponse(request);
         return response;
      } catch (ClientException e) {
         throw e;
      }
     }
    Note

    accessKeyId and accessKeySecret: the AccessKey information obtained from the RAM console for the RAM user who plays the RAM role. roleArn: the Alibaba Cloud Resource Name (ARN) value on the details page of the RAM role, as shown in the following figure. roleSessionName: the custom session name used to identify a user in subsequent audits. policy: the finer-grained permission control over each granted permission. String policy = "{\n" + " \"Version\": \"1\",\n" + " \"Statement\": [\n" + " {\n" + " \"Action\": \"vod:*\",\n" + " \"Resource\": \"*\",\n" + " \"Effect\": \"Allow\"\n" + " }\n" + " ]\n" + "}";

  4. Deliver the obtained data to the client, which can use the STS temporary AccessKey to call upload APIs and upload videos.

Appendix