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.

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;
using System.Collections.Generic;

namespace Aliyun.Acs.vod.Sdk.Sample
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // Constructs a request.
                GetPlayInfoRequest request = new GetPlayInfoRequest();
                request.VideoId = "<Your video ID>";
                //request.AuthTimeout = 3600;
                // Initializes the client.
                DefaultAcsClient client = InitVodClient();
                // Initiates the request and obtains a response.
                GetPlayInfoResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                Console.WriteLine("VideoBase.Title = " + response.VideoBase.Title);
                List<GetPlayInfoResponse.GetPlayInfo_PlayInfo> playInfoList = response.PlayInfoList;
                foreach (var playInfo in response.PlayInfoList)
                {
                    Console.WriteLine("PlayInfoList.PlayURL = " + playInfo.PlayURL);
                }
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

Obtain the video playback credential

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.Sample
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // Constructs a request.
                GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
                request.VideoId = "<Your video ID>";
                //request.AuthInfoTimeout = 3000;
                // Initializes the client.
                DefaultAcsClient client = InitVodClient();
                // Initiates the request and obtains a response.
                GetVideoPlayAuthResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                Console.WriteLine("VideoMeta.Title = " + response.VideoMeta.Title);
                Console.WriteLine("PlayAuth = " + response.PlayAuth);
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}