網(wǎng)站開發(fā)之對接阿里云視頻點播

2023-03-27    分類: 網(wǎng)站建設

阿里云
1.首先在阿里云控制中心找到視頻點播,如果沒有開通就需要先開通服務,好先購買存儲流量包和播放流量包,不然就會以播放流量收費比較貴。

設置域名
添加域名
加速區(qū)域添加加速域名,默認加速是上海地區(qū),在配置管理-存儲管理可以找到存儲地址
添加好域名就要配置安全策略,比例黑白名單,指定只能在哪個域名下播放,是否支持瀏覽器直接打開等一些防止視頻被別人下載,需要在url鑒權設置兩個key
4.Php代碼 獲取音視頻播放憑證
<?php
require'aliyun-php-sdk-core/Config.php';//假定您的源碼文件和aliyun-php-sdk處于同一目錄
usevod\Request\V20170321asvod;
classAliyun{
functioninit_vod_client($accessKeyId,$accessKeySecret){
$regionId='cn-shenzhen';//點播服務所在的Region,國內(nèi)請?zhí)頲n-shanghai,不要填寫別的區(qū)域
$profile=DefaultProfile::getProfile($regionId,$accessKeyId,$accessKeySecret);
returnnewDefaultAcsClient($profile);
}
functionget_play_info($client,$videoId){
$request=newvod\GetPlayInfoRequest();
$request->setVideoId($videoId);
$regionId='cn-shenzhen';
$request->setAuthTimeout(3600*24);//播放地址過期時間(只有開啟了URL鑒權才生效),默認為3600秒,支持設置最小值為3600秒
$request->setAcceptFormat('JSON');
$arr=$client->getAcsResponse($request);
return$arr;
}
functiontestGetVideoPlayAuth($client,$videoId){
$request=newvod\GetVideoPlayAuthRequest();
$regionId='cn-shenzhen';
$request->setAcceptFormat('JSON');
$request->setRegionId($regionId);
$request->setVideoId($videoId);//視頻ID
$response=$client->getAcsResponse($request);
return$response;
}
}
?>
functiongetAuth($videoId){
vendor('Aliyun.Aliyun');
$video=new\Aliyun();//引入sdk
$accid='xxxxxxxxxx';
$secret="'xxxxxxxxxx'";
$res=$video->init_vod_client($accid,$secret);
$ress=$video->testGetVideoPlayAuth($res,$videoId);
$url=json_decode(json_encode($ress),true);
$str=$url['PlayAuth'];
return$str;
//return$resss['PlayAuth'];
}
或者也可以獲取播放地址
functiongetPlayUrl($videoId){
vendor('Aliyun.Aliyun');
$video=new\Aliyun();
$accid='xxxxxxxxxx'
$secret='xxxxxxxxxx';
$res=$video->init_vod_client($accid,$secret);
$ress=$video->get_play_info($res,$videoId);
$url=json_decode(json_encode($ress),true);
//$str=$url['PlayAuth'];
$str=$url['PlayInfoList']['PlayInfo'][0]['PlayURL'];
return$str;
//return$resss['PlayAuth'];
}
5.前端播放代碼
引入播放器
<linkrel="stylesheet"href="https://g.alicdn.com/de/prismplayer/2.9.19/skins/default/aliplayer-min.css"/>
<scriptcharset="utf-8"type="text/javascript"src="https://g.alicdn.com/de/prismplayer/2.9.19/aliplayer-min.js"></script>
<scriptcharset="utf-8"type="text/javascript"src="https://g.alicdn.com/de/prismplayer/2.9.19/aliplayer-h5-min.js"></script>
<divclass="videoprism-player""id="J_prismPlayer"></div>
<script>
varplayer=newAliplayer({
id:'J_prismPlayer',
width:'100%',
height:'500px',
autoplay:true,
vid:'{$videoId}',//必選參數(shù)。音視頻ID。示例:1e067a2831b641db90d570b6480f****。
playauth:'{$PlayAuth}',//必選參數(shù)。音視頻播放憑證。
},function(player){
console.log('Theplayeriscreated.')
});
</script>
這里是通過音頻id 和播放憑證播放。還有直接獲取播放地址播放。

網(wǎng)站欄目:網(wǎng)站開發(fā)之對接阿里云視頻點播
網(wǎng)頁路徑:http://www.muchs.cn/news22/248222.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供微信小程序商城網(wǎng)站、網(wǎng)站內(nèi)鏈App設計、軟件開發(fā)、動態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設計