阿里云视频点播服务与谷粒学院整合视频点播技术
一.应用场景
- 音视频网站:无论是初创视频服务企业,还是已拥有海量视频资源,可定制化的点播服务帮助客户快速搭建拥有极致观看体验、安全可靠的视频点播应用。
- 短视频:集音视频拍摄、特效编辑、本地转码、高速上传、自动化云端转码、媒体资源管理、分发加速、播放于一体的完整短视频解决方案。目前已帮助1000+APP快速实现手机短视频功能。
- 直播转点播:将直播流同步录制为点播视频,用于回看。并支持媒资管理、媒体处理(转码及内容审核/智能首图等AI处理)、内容制作(云剪辑)、CDN分发加速等一系列操作。
- 在线教育:为在线教育客户提供简单易用、安全可靠的视频点播服务。可通过控制台/API等多种方式上传教学视频,强大的转码能力保证视频可以快速发布,覆盖全网的加速节点保证学生观看的流畅度。防盗链、视频加密等版权保护方案保护教学内容不被窃取。
- 视频生产制作:提供在线可视化剪辑平台及丰富的OpenAPI,帮助客户高效处理、制作视频内容。除基础的剪切拼接、混音、遮标、特效、合成等一系列功能外,依托云剪辑及点播一体化服务还可
- 实现标准化、智能化剪辑生产,大大降低视频制作的槛,缩短制作时间,提升内容生产效率。
- 内容审核:应用于短视频平台、传媒行业审核等场景,帮助客户从从语音、文字、视觉等多维度精准识别视频、封面、标题或评论的违禁内容进行AI智能审核与人工审核。
二.功能介绍
三.视频点播的整体流程
四.使用实例
4.1根据视频地址进行播放(未加密的视频)
直接根据视频的地址进行视频的播放
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.9.8/skins/default/aliplayer-min.css" /><script charset="utf-8" type="text/javascript" src="https://g.alicdn.com/de/prismplayer/2.9.8/aliplayer-min.js"></script><!-- <link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.8.1/skins/default/aliplayer-min.css" /><script charset="utf-8" type="text/javascript"src="https://g.alicdn.com/de/prismplayer/2.8.1/aliplayer-min.js"></script> -->
</head><body><body><div class="prism-player" id="J_prismPlayer"></div> <script>var player = new Aliplayer({id: 'J_prismPlayer',width: '50%',autoplay: false,cover: 'https://sunset-education.oss-cn-beijing.aliyuncs.com/2021/07/22/07da8844645c4485a8fe7d18a23353c003.jpg',//播放配置source : 'https://outin-d7002059ed2311eb821700163e1c955c.oss-cn-shanghai.aliyuncs.com/sv/352c58b0-17b05d4fe47/352c58b0-17b05d4fe47.mp4?Expires=1628246744&OSSAccessKeyId=LTAIVVfYx6D0HeL2&Signature=VXcZEUAdJjAC7TY%2Fgy8yJGZGqjE%3D',},function(player){console.log('播放器创建好了。')});</script></body></body></html>
4.2根据视频的播放凭证进行播放
步骤:
- 根据阿里云上传的视频id获取视频的播放凭证
- 根据播放凭证获取视频的播放信息
注意:那一大段很长的就是视频的凭证,现在是直接给,后期整合后则是根据视频的id进行获取
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.9.8/skins/default/aliplayer-min.css" /><script charset="utf-8" type="text/javascript" src="https://g.alicdn.com/de/prismplayer/2.9.8/aliplayer-min.js"></script>
</head><body><body><div class="prism-player" id="J_prismPlayer"></div> <script>var player = new Aliplayer({id: 'J_prismPlayer',width: '50%',autoplay: false,cover: 'https://sunset-education.oss-cn-beijing.aliyuncs.com/2021/07/22/07da8844645c4485a8fe7d18a23353c003.jpg',encryptType:'1',//如果播放加密视频,则需设置encryptType=1,非加密视频无需设置此项vid : '5adbc05402e048aab30121542f617476',playauth : 'eyJTZWN1cml0eVRva2VuIjoiQ0FJU2h3TjFxNkZ0NUIyeWZTaklyNVdOT2VpTnVJZHM3YmVjZTAzcGwzVUVPL2hVaUtmU2h6ejJJSHBOZTNocUIrMGZzUGt3bEdsVTZmZ2Nsck1xRWNVYUhSYWFQWll0czhRTHJsNzZKcExGc3QySj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iTWVkaWFJZFwiOlwiNWFkYmMwNTQwMmUwNDhhYWIzMDEyMTU0MmY2MTc0NzZcIixcIlNpZ25hdHVyZVwiOlwiQThtUDNKUUVIa1FEcWJZYzdoZytlUDJESjUwPVwifSIsIlZpZGVvTWV0YSI6eyJTdGF0dXMiOiJOb3JtYWwiLCJWaWRlb0lkIjoiNWFkYmMwNTQwMmUwNDhhYWIzMDEyMTU0MmY2MTc0NzYiLCJUaXRsZSI6InZpZGVvLm1wNCIsIkNvdmVyVVJMIjoiaHR0cDovL291dGluLWQ3MDAyMDU5ZWQyMzExZWI4MjE3MDAxNjNlMWM5NTVjLm9zcy1jbi1zaGFuZ2hhaS5hbGl5dW5jcy5jb20vNWFkYmMwNTQwMmUwNDhhYWIzMDEyMTU0MmY2MTc0NzYvc25hcHNob3RzL2Q1ZjM1YzU1ZWE1YzQyODViODc4YTI3YmZjZDIwNTQ3LTAwMDAxLmpwZz9FeHBpcmVzPTE2Mjc4MDkwMjImT1NTQWNjZXNzS2V5SWQ9TFRBSVZWZll4NkQwSGVMMiZTaWduYXR1cmU9MkVVQnY4dXElMkZDaFlJdFVrWmlWdXNSOTg5OHMlM0QiLCJEdXJhdGlvbiI6MTIuNTE1fSwiQWNjZXNzS2V5SWQiOiJTVFMuTlY4clI5VVhNWnV3eWtYc3VRN3d4Z2J5ZSIsIkFjY2Vzc0tleVNlY3JldCI6IkVUVW94Tm44RHdicnZSd1hnd21meE1zTkZVVWRIMzVjaTFwdlVoUmVYclJGIiwiUmVnaW9uIjoiY24tc2hhbmdoYWkiLCJDdXN0b21lcklkIjoxMjI3MDI2ODU1NTg0NzUzfQ==',},function(player){console.log('播放器创建好了。')});</script></body></body></html>
五.谷粒学院整合阿里云视频点播服务
-
创建一个新的模块
-
导入相关依赖
<dependencies><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-core</artifactId></dependency><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-vod</artifactId></dependency><dependency><groupId>com.google.code.gson</groupId><artifactId>gson</artifactId></dependency><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-core</artifactId></dependency><dependency><groupId>com.aliyun.oss</groupId><artifactId>aliyun-sdk-oss</artifactId></dependency><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-vod</artifactId></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId></dependency><dependency><groupId>org.json</groupId><artifactId>json</artifactId></dependency><dependency><groupId>com.google.code.gson</groupId><artifactId>gson</artifactId></dependency><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-sdk-vod-upload</artifactId></dependency></dependencies>
- 将阿里云的keyid等配置好
- 创建一个工具类,用来创建DefaultAcsClient对象
package com.sunset.vod.utils;import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;/*** 初始化操作,创建DefaultAcsClient对象*/
public class InitObject {public static DefaultAcsClient initVodClient(String accessKeyId, String accessKeySecret) throws ClientException {String regionId = "cn-shanghai"; // 点播服务接入区域DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);DefaultAcsClient client = new DefaultAcsClient(profile);return client;}
}
-
根据视频id获取视频凭证,并传递给前端使用
// 根据视频id获取视频播放凭证@GetMapping("/getPlayAuth/{id}")public Result getPlayAuth(@PathVariable String id){try { // 创建初始化对象DefaultAcsClient defaultAcsClient = InitObject.initVodClient(ConstantVodUtils.ACCESS_KEY_ID, ConstantVodUtils.ACCESS_KEY_SECRET);// 创建获取视频凭证的request和response对象GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest(); // 设置视频id值request.setVideoId(id); // 调用初始化对象的方法GetVideoPlayAuthResponse response = defaultAcsClient.getAcsResponse(request); // 获取凭证String playAuth = response.getPlayAuth();System.out.println("==========="+playAuth);return Result.ok().data("playAuth",playAuth);}catch (Exception e){throw new SunsetException(20001,"播放视频失败");}}
-
前端定义接口,并进行调用
import request from '@/utils/request'export default{// 根据视频id获取视频播放凭证getPlayAuth(id){return request({url:'/eduvod/video/getPlayAuth/'+id,method:'get'})}
}
<template><div><!-- 阿里云视频播放器样式 --><!-- <link rel="stylesheet"href="https://g.alicdn.com/de/prismplayer/2.9.8/skins/default/aliplayer-min.css"/> --><!-- 阿里云视频播放器脚本 --><!-- <script charset="utf-8" type="text/javascript" src="https://g.alicdn.com/de/prismplayer/2.9.8/aliplayer-min.js"></script> --><linkrel="stylesheet"href="https://g.alicdn.com/de/prismplayer/2.8.1/skins/default/aliplayer-min.css"/><scriptcharset="utf-8"type="text/javascript"src="https://g.alicdn.com/de/prismplayer/2.8.1/aliplayer-min.js"/><!-- 定义播放器dom --><div id="J_prismPlayer" class="prism-player" /></div>
</template><script>
import vodApi from '@/api/vod'
export default {layout: 'video',//应用video布局data(){return{// playAuth:'',// vid:''}},asyncData({ params, error }) {return vodApi.getPlayAuth(params.vid).then(response=>{return {vid:params.vid,playAuth:response.data.data.playAuth}})},mounted(){//页面渲染之后执行这个方法,因为前面是异步请求视频的播放凭证,所以使用created的话,可能获取不到数据new Aliplayer({id: 'J_prismPlayer',vid: this.vid, // 视频idplayauth: this.playAuth, // 播放凭证// source : 'https://outin-d7002059ed2311eb821700163e1c955c.oss-cn-shanghai.aliyuncs.com/sv/352c58b0-17b05d4fe47/352c58b0-17b05d4fe47.mp4?Expires=1628246744&OSSAccessKeyId=LTAIVVfYx6D0HeL2&Signature=VXcZEUAdJjAC7TY%2Fgy8yJGZGqjE%3D',encryptType: '1', // 如果播放加密视频,则需设置encryptType=1,非加密视频无需设置此项width: '100%',height: '500px',cover: 'http://guli.shop/photo/banner/1525939573202.jpg', // 封面qualitySort: 'asc', // 清晰度排序mediaType: 'video', // 返回音频还是视频autoplay: false, // 自动播放isLive: false, // 直播rePlay: false, // 循环播放preload: true,controlBarVisibility: 'hover', // 控制条的显示方式:鼠标悬停useH5Prism: true, // 播放器类型:html5}, function(player) {console.log('播放器创建成功')})},methods:{init(){vodApi.getPlayAuth(this.vid).then(response=>{this.playAuth = response.data.data.playAuth// console.log(this.vid)// console.log(this.playAuth)})},}};
</script><style>
</style>
- 测试
成功!!!