All Products
Search
Document Center

Have fun with long videos

Last Updated: May 27, 2020

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.

  • Download the LongVideo SDK:You can click here to directly download ApsaraVideo Player SDK on your video player without applying for a license.

  • Compile and run the demo:We provide a set of SDK source code for your reference. You can clickhere to download and use the source code package for a quicker launch of your application.For more information about the demo compilation, see LongVideo solution integration for Android and LongVideo solution integration for iOS.

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 for VOD

ApsaraVideo for 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 for 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 for 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 for VOD

  1. Activate ApsaraVideo for VOD.

  2. Learn about the product information on the product page of ApsaraVideo for 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 for VOD console and start using the service.

  5. Add a domain name.

  6. In the ApsaraVideo for 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: 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:

    • 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 for VOD, see Get started with ApsaraVideo for VOD.

AppServer

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

    To use ApsaraVideo for VOD APIs, you need to use an AccessKey for access to ApsaraVideo for 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 for 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: 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:

    1. static AssumeRoleResponse assumeRole(String accessKeyId, String accessKeySecret,
    2. String roleArn, StringroleSessionName, String policy,
    3. ProtocolType protocolType) throws ClientException {
    4. try {
    5. // Create an Alibaba Cloud AcsClient for initiating API requests.
    6. IClientProfile profile = DefaultProfile.getProfile(REGION_CN_HANGZHOU, accessKeyId, accessKeySecret);
    7. DefaultAcsClient client = new DefaultAcsClient(profile);
    8. // Create an AssumeRoleRequest and set request parameters.
    9. final AssumeRoleRequest request = new AssumeRoleRequest();
    10. request.setVersion(STS_API_VERSION);
    11. request.setMethod(MethodType.POST);
    12. request.setProtocol(protocolType);
    13. request.setRoleArn(roleArn);
    14. request.setRoleSessionName(roleSessionName);
    15. request.setPolicy(policy);
    16. // Initiate the request and obtain a response.
    17. final AssumeRoleResponse response = client.getAcsResponse(request);
    18. return response;
    19. } catch (ClientException e) {
    20. throw e;
    21. }
    22. }
    • 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.
      1. String policy = "{\n" +
      2. " \"Version\": \"1\",\n" +
      3. " \"Statement\": [\n" +
      4. " {\n" +
      5. " \"Action\": \"vod:*\",\n" +
      6. " \"Resource\": \"*\",\n" +
      7. " \"Effect\": \"Allow\"\n" +
      8. " }\n" +
      9. " ]\n" +
      10. "}";
  4. Deliver the obtained data to the client, which can use the STS temporary AccessKey to call upload APIs and upload videos.

Appendix