研究了几天,又加上付了9.9最后出的结果
准备1 首先你要有一个阿里云账号,且实名认证过了
其次2 你要https://usercenter.console.aliyun.com/#/manage/ak 设置好AccessKey ID,Access Key Secret 只主的就可了否则多设置一下,使用子账号权限的也可以。
再次3 vs引入git,我是vs2013 git 的 aliyun-net-sdk-vod.2.15.8.nupkg,aliyun-net-sdk-core.1.5.3.nupkg.这里多说点
1 https://www.nuget.org/profiles/aliyun-openapi-sdk 下载的最新版本。core,vod 也是一起下的nupkg格式文件
2 nupkg下载存储到本地任意文件夹,打开vs2013目标项目,之后在vs的 菜单- 工具 -NuGet包管理器-管理解决方案
的。。。-左下角 设置 -指定对应文件夹-之后返回GuGet程序包,安装到指定项目就可以了.
第四 程序加载之后,视图页面,引用
<link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.8.2/skins/default/aliplayer-min.css" />
<script charset="utf-8" type="text/javascript" src="https://g.alicdn.com/de/prismplayer/2.8.2/aliplayer-min.js"></script>
<div class="prism-player" id="J_prismPlayer"></div>
<script>
var player = new Aliplayer({
id: 'J_prismPlayer',
width: '100%',
autoplay: false,
//支持播放地址播放,此播放优先级最高
//source: '',
//播放方式二:点播用户推荐
vid: '@ViewBag.RequestId',
playauth: '@ViewBag.PlayAuth',
cover: '@ViewBag.CoverURL',
}, function (player) {
console.log('播放器创建好了。')
});
</script>
控制器:
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;
public class HomeController : BaseController
{
public static DefaultAcsClient InitVodClient(string accessKeyId, string accessKeySecret)
{
// 点播服务接入区域
string regionId = "cn-shanghai";
IClientProfile profile = DefaultProfile.GetProfile(regionId, accessKeyId, accessKeySecret);
// DefaultProfile.AddEndpoint(regionId, regionId, "vod", "vod." + regionId + ".aliyuncs.com");
return new DefaultAcsClient(profile);
}
public ActionResult Index()
{
return View();
}
public ActionResult test()
{
ViewBag.PlayAuth = "";
ViewBag.RequestId = "";
//try
//{
// 构造请求
//GetPlayInfoRequest request = new GetPlayInfoRequest();
//request.VideoId = "XXXXXXXXXXX";
request.AuthTimeout = 3600;
初始化客户端
//DefaultAcsClient client = InitVodClient("XXXXXX", "XXXXXXXX");
发起请求,并得到 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)
//{
// ViewBag.viedo = playInfo.PlayURL;
// // Console.WriteLine("PlayInfoList.PlayURL = " + playInfo.PlayURL);
//}
// int t = 1;
//}
//catch (ServerException ex)
//{
// Console.WriteLine(ex.ToString());
//}
//catch (ClientException ex)
//{
// Console.WriteLine(ex.ToString());
//}
//try
//{
//构造请求
GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
request.VideoId = "XXXXXXXX";
//request.AuthInfoTimeout = 3000;
// 初始化客户端
DefaultAcsClient client = InitVodClient("XXXXX", "XXXXXXX");
// 发起请求,并得到 response
GetVideoPlayAuthResponse response = client.GetAcsResponse(request);
//Console.WriteLine("RequestId = " + response.RequestId);
//Console.WriteLine("VideoMeta.Title = " + response.VideoMeta.Title);
//Console.WriteLine("PlayAuth = " + response.PlayAuth);
ViewBag.RequestId = response.VideoMeta.VideoId;
ViewBag.CoverURL = response.VideoMeta.CoverURL;
ViewBag.PlayAuth = response.PlayAuth;
//}
//catch (ServerException ex)
//{
// Console.WriteLine(ex.ToString());
//}
//catch (ClientException ex)
//{
// Console.WriteLine(ex.ToString());
//}
return View();
}
}
就可以了,对应的说明页面
前端播放器说明页 https://help.aliyun.com/document_detail/125570.html?spm=a2c4g.11186623.2.24.22c71fc17tBQhG#h2-sdk-5
https://help.aliyun.com/document_detail/125572.html?spm=a2c4g.11186623.6.1085.7d976a58BfFsJt 更详细的页面说明