| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 | 
							- <?php
 
- namespace Live\Lib;
 
- use Dever;
 
- Dever::apply('sdk/qiniu', 'live');
 
- class Qiniu
 
- {
 
-     private $stream;
 
-     private $config;
 
-     private $space;
 
-     # 连接
 
-     public function __construct($config)
 
-     {
 
-         $this->config = $config;
 
-         $mac = new \Qiniu\Pili\Mac($this->config['appkey'], $this->config['appsecret']);
 
-         $client = new \Qiniu\Pili\Client($mac);
 
-         $this->space = $client->hub($this->config['space']);
 
-     }
 
-     # 创建新流
 
-     public function create($name)
 
-     {
 
-         $result = $this->space->create($name);
 
-         return $this->getInfo($name);
 
-     }
 
-     # 查询流
 
-     public function get($name)
 
-     {
 
-         if (!$this->stream) {
 
-             $this->stream = $this->space->stream($name);
 
-         }
 
-         return $this->stream;
 
-     }
 
-     # 查询流的信息
 
-     public function getInfo($name)
 
-     {
 
-         $stream = $this->get($name);
 
-         return $stream->info();
 
-     }
 
-     # 获取直播状态
 
-     public function getLiveStatus($name)
 
-     {
 
-         $stream = $this->get($name);
 
-         return $stream->liveStatus();
 
-     }
 
-     # 列出所有流
 
-     public function gets($prefix = '', $limit = 10000)
 
-     {
 
-         return $this->space->listStreams($prefix, $limit, '');
 
-     }
 
-     # 列出所有正在直播的流
 
-     public function getLives($prefix = '', $limit = 10000)
 
-     {
 
-         return $this->space->listLiveStreams($prefix, $limit, '');
 
-     }
 
-     # 启动流
 
-     public function start($name = '')
 
-     {
 
-         $stream = $this->get($name);
 
-         $stream->enable();
 
-         return $this->getLiveStatus($name);
 
-     }
 
-     # 禁用流
 
-     public function stop($name = '', $num = 120)
 
-     {
 
-         $stream = $this->get($name);
 
-         $stream->disable(time() + $num);
 
-         return $this->getLiveStatus($name);
 
-     }
 
-     # 保存直播数据
 
-     public function save($name, $start, $end)
 
-     {
 
-         $stream = $this->get($name);
 
-         return $stream->saveas(array("format" => "mp4"), $start, $end);
 
-     }
 
-     # 保存直播截图
 
-     public function savePic($name)
 
-     {
 
-         $stream = $this->get($name);
 
-         return $stream->snapshot(array("format" => "jpg"));
 
-     }
 
-     # 查看历史直播流
 
-     public function history($name)
 
-     {
 
-         $stream = $this->get($name);
 
-         return $stream->historyActivity(0, 0);
 
-     }
 
-     # 查询推流历史
 
-     public function update($name, $convert)
 
-     {
 
-         $stream = $this->get($name);
 
-         $stream->updateConverts($convert);
 
-         return $stream->info();
 
-     }
 
-     # 获取推流地址
 
-     public function getRtmp($name, $time = 3600)
 
-     {
 
-         $url = \Qiniu\Pili\RTMPPublishURL("publish-rtmp.test.com", $this->config['space'], $name, 3600, $this->config['appkey'], $this->config['appsecret']);
 
-         return $url;
 
-     }
 
-     # 获取直播地址
 
-     public function getPlay($name)
 
-     {
 
-         //高清、标清、普清
 
-         $url['rtmp'] = $this->getRtmpPlay($name);
 
-         $url['hls'] = $this->getHlsPlay($name);
 
-         $url['hdl'] = $this->getHdlPlay($name);
 
-         $url['pic'] = $this->getPicPlay($name);
 
-         return $url;
 
-     }
 
-     # 获取直播地址
 
-     public function getRtmpPlay($name)
 
-     {
 
-         $url = \Qiniu\Pili\RTMPPlayURL("live-rtmp.test.com", $this->config['space'], $name);
 
-         return $url;
 
-     }
 
-     # HLS 直播地址
 
-     public function getHlsPlay($name)
 
-     {
 
-         $url = \Qiniu\Pili\HLSPlayURL("live-hls.test.com", $this->config['space'], $name);
 
-         return $url;
 
-     }
 
-     # HDL 直播地址
 
-     public function getHdlPlay($name)
 
-     {
 
-         $url = \Qiniu\Pili\HDLPlayURL("live-hdl.test.com", $this->config['space'], $name);
 
-         return $url;
 
-     }
 
-     # 截图直播地址
 
-     public function getPicPlay($name)
 
-     {
 
-         $url = \Qiniu\Pili\SnapshotPlayURL("live-snapshot.test.com", $this->config['space'], $name);
 
-         return $url;
 
-     }
 
- }
 
 
  |