七牛直播服务sdk

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010454239/article/details/53868849

最近要做一个直播的项目,用的七牛的直播服务,看七牛的服务端sdk比较繁琐,还有很多注释是我厌烦的英文注释,做了一个基类对其调用应用此基类只要去七牛官网下载直播服务服务端php sdk然后像第一行代码似的引用sdk中的Pili_v2.php 即可.

也可直接用我打包好的,解压出来Lite.class.php就是此文件直接引用就ok 传送门:链接:https://pan.baidu.com/s/1kVfmUGJ密码: ri72

下面是基类的代码:

 
 
 
 
<?php

require(join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'lib', 'Pili_v2.php')));
class Qiniu_Lite
{
    public  $push_domin = '';    //推流域名
    public  $pull_domin = '';    //拉流域名
    public  $hubName = '';       //直播空间名
    public  $ak = '';             //AccessKey
    public  $sk = '';             //SecretKey
    private $mac ;
    private $client;
    private $hub;
    public function __construct()
    {
        $this->mac = new Qiniu\Pili\Mac($this->ak, $this->sk);
        $this->client = new Qiniu\Pili\Client($this->mac);
        $this->hub = $this->client->hub($this->hubName);
        $this->push_domin = $this->push_domin;
        $this->pull_domin = $this->pull_domin;
    }

    /**
     * 获取推流地址
     * @param $streamKey 流名
     * @return mixed
     */
    public function publishUrl($streamKey){
        return Qiniu\Pili\RTMPPublishURL($this->push_domin, $this->hubName, $streamKey, 3600, $this->ak, $this->sk);
    }

    /**
     * 获取拉流地址(RTMP直播地址)
     * @param $streamKey
     * @return mixed
     */
    public function playUrl($streamKey){
        return Qiniu\Pili\RTMPPlayURL($this->pull_domin, $this->hubName, $streamKey);
    }
    /**
     * 获取流信息
     * @param $streamKey 流名
     * @return array
     */
    public function info($streamKey){
        $stream = $this->hub->stream($streamKey);
        return $stream->info();
    }

    /**
     * 启用流
     * @param $streamKey 流名
     * @return mixed
     */
    public function enable($streamKey){
        $stream = $this->hub->stream($streamKey);
        return $stream->disable(0);
    }

    /**
     * 禁用推流和拉流
     * @param $streamKey 流名
     * @param $time 恢复推流时间时间戳,不填则永久封禁
     * @return mixed
     */
    public function disable($streamKey,$time=-1){
        $stream = $this->hub->stream($streamKey);
        return $stream->disable($time);
    }

    /**
     * 查询直播状态
     * @param $streamKey 流名
     * @return mixed
     */
    public function liveStatus($streamKey){
        $stream = $this->hub->stream($streamKey);
        return $stream->liveStatus();
    }

    /**
     * 保存直播回放
     * 将指定时间段的直播保存到存储空间里面。
     * @param $streamKey 流名
     * @param null $start 整数,可选,Unix 时间戳,要保存的直播的起始时间,不指定或 0 值表示从第一次直播开始。
     * @param null $end 整数,可选,Unix 时间戳,要保存的直播的结束时间,不指定或 0 值表示当前时间。
     * @param $fname 保存的文件名,可选,不指定系统会随机生成。
     * @return mixed
     */
    public function save($streamKey,$start=NULL,$end=NULL,$fname=''){
        $stream = $this->hub->stream($streamKey);
        return $stream->save($start,$end,$fname);
    }

    /**
     * 直播历史记录
     * @param $streamKey 流名
     * @param null $start 整数,可选,Unix 时间戳,起始时间,不指定或 0 值表示不限制起始时间。
     * @param null $end 整数,可选,Unix 时间戳,结束时间,不指定或 0 值表示当前时间。
     * @return mixed
     */
    public function historyActivity($streamKey,$start=NULL,$end=NULL){
        $stream = $this->hub->stream($streamKey);
        return $stream->historyActivity($start,$end);
    }

    /**
     * 查询直播空间中的流列表。
     * @param $live  布尔值,可选,true 表示查询的是正在直播的流,不指定表示返回所有的流。
     * @param $prefix  字符串,可选,限定只返回带以 prefix 为前缀的流名,不指定表示不限定前缀。
     * @param $limit  整数,可选,限定返回的流个数,不指定表示遵从系统限定的最大个数。
     * @param $marker  字符串,可选,上一次查询返回的标记,用于提示服务端从上一次查到的位置继续查询,不指定表示从头查询。
     */
    public function listLiveStreams($live,$prefix, $limit, $marker){
        return $this->hub->_list($live, $prefix, $limit, $marker);
    }

}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

猜你喜欢

转载自blog.csdn.net/u010454239/article/details/53868849