新聞中心
本文操作環(huán)境:Windows7系統(tǒng),php7.1版,Dell G3電腦。

在富寧等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站制作、成都網(wǎng)站設(shè)計 網(wǎng)站設(shè)計制作定制網(wǎng)站開發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站設(shè)計,全網(wǎng)整合營銷推廣,外貿(mào)網(wǎng)站建設(shè),富寧網(wǎng)站建設(shè)費用合理。
php怎么實現(xiàn)在線直播功能?
php 七牛云實現(xiàn)直播功能:
一:最近在做一個直播賣貨的項目,后臺搭建好了準(zhǔn)備接入直播,搜了幾家阿里,TX和七牛,結(jié)果阿里的直播php只有代碼沒有文檔,TX的我朋友說代碼比較亂就不考慮了,上了七牛注冊了一個賬戶,申請直播空間的時候被域名卡主了,已經(jīng)備案的域名還要再網(wǎng)站公安備案一次
https://developer.qiniu.com/af/kb/3987/how-to-make-website-and-inquires-the-police-put-on-record-information?ref=support.qiniu.com
又搜了搜發(fā)現(xiàn)涉及網(wǎng)絡(luò)表演業(yè)務(wù)的,需辦理《網(wǎng)絡(luò)文化經(jīng)營許可證》,請咨詢當(dāng)?shù)厝嗣裾幕姓块T,等待申請完以后在進(jìn)行下一步。
二:域名備案終于好了,開始搞第二步,實現(xiàn)直播功能,移動端可以參考七牛云SDK,下面是服務(wù)端推流案例,本次使用的是rtmp流實現(xiàn)直播,在控制臺找到直播云服務(wù),創(chuàng)建直播云空間
創(chuàng)建好直播空間后會生成幾個二級域名,按需要將域名解析出來,然后就到了下面的樣子
代碼運(yùn)行起來后會在直播流中看到你說創(chuàng)建的直播流播放歷史等信息
安裝composer包
php composer.phar require qiniu/php-sdk
再vendor/pili-engineering/pili-sdk-php.v2里能找到兩個案例,一個是直播的,一個是連麥的,這次先實現(xiàn)直播,下一篇再更新一下連麥
accessKey = config("qiniu.accessKey");
$this->secretKey = config("qiniu.secretKey");
$this->hubName = config("qiniu.bucket");
parent::__construct();
}
/**
*開啟直播
*/
public function liveStart(Request $request)
{
$userInfo = parent::getAuthenticatedUser($msg);
if (isset($userInfo['user']) && !empty($userInfo['user'])) {
$request->offsetSet('user_id', $userInfo['user']['id']);
} else {
return $this->sendResponse($msg, 'error', '', 401);
}
$data = $request->all();
$broadcast = app(BroadcastRepositoryEloquent::class)->findWhere(['type' => $data['type'], 'user_id' => $data['user_id']])->first();
if (empty($broadcast)) {
return $this->sendResponse(trans('admin.operate_failed') . '未找到直播間');
}
$broadcast['name'] = $data['name'];
//創(chuàng)建hub
$mac = new Mac($this->accessKey, $this->secretKey);
$client = new Client($mac);
$hub = $client->hub($this->hubName);
//獲取stream
$streamKey = $broadcast['show_id'];
$stream = $hub->stream($streamKey);
$list = $hub->listStreams($streamKey, 1, "");
//如果沒找到對應(yīng)的直播流創(chuàng)建新直播流
if (count($list['keys']) == 0) {
//獲取stream
$hub->create($streamKey);
}
if ($data['type'] == 0) {
$result = $this->updateShop($broadcast, $streamKey, $msg);
if ($result == false) {
return $this->sendResponse(trans('admin.operate_failed') . $msg);
}
} else {
$result = $this->updateCurriculum($broadcast, $streamKey, $msg);
if ($result == false) {
return $this->sendResponse(trans('admin.operate_failed') . $msg);
}
}
return $this->sendResponse(trans('admin.operate_succeeded'), 'succ', ['p_href' => $broadcast['p_href']]);
}
//更新商城直播間
public function updateShop($broadcast, $streamKey, &$msg = '')
{
//獲取推流地址
$p_href = RTMPPublishURL("pili-publish.chengdulihong.com", $this->hubName, $streamKey, 3600, $this->accessKey, $this->secretKey);
//獲取播放地址
$g_href = RTMPPlayURL("pili-publish.chengdulihong.com", $this->hubName, $streamKey);
//截圖直播地址
$pic = SnapshotPlayURL("pili-publish.chengdulihong.com", $this->hubName, $streamKey);
//更新直播間狀態(tài)
$u_broadcast = $broadcast->fill(['name' => $broadcast['name'], 'chatroom_status' => 0, 'p_href' => $p_href, 'g_href' => $g_href, 'pic' => $pic])->save();
if ($u_broadcast == false) {
return $this->sendResponse(trans('admin.operate_failed') . '更新直播間出錯');
}
return true;
} 網(wǎng)頁題目:php怎么實現(xiàn)在線直播功能
新聞來源:http://www.dlmjj.cn/article/dhjchoc.html


咨詢
建站咨詢
