音视频播放

本篇文档提供了.NET SDK音视频播放模块相关功能的API调用示例。包含获取播放地址、获取视频播放凭证。

初始化客户端

使用前请先初始化客户端,请参见初始化

获取播放地址

调用GetPlayInfo接口,完成获取播放地址功能。

接口参数和返回字段请参见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
            {
                // 构造请求
                GetPlayInfoRequest request = new GetPlayInfoRequest();
                request.VideoId = "<your VideoId>";
                // request.AuthTimeout = 3600;
                // 初始化客户端
                DefaultAcsClient client = InitVodClient();
                // 发起请求,并得到 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());
            }
        }
    }
}

获取视频播放凭证

调用GetVideoPlayAuth接口,完成获取视频播放凭证功能。

接口参数和返回字段请参见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
            {
                // 构造请求
                GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
                request.VideoId = "<your VideoId>";
                //request.AuthInfoTimeout = 3000;
                // 初始化客户端
                DefaultAcsClient client = InitVodClient();
                // 发起请求,并得到 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());
            }
        }
    }
}