上传视频云点播和查看视频

//上传云点播

public function upload_video()

{

$upload = new Upload();

$upload->maxSize = 0 ;// 设置附件上传大小

$upload->exts = array('wmv','asf','asx','rmvb','rm','mp4','3gb','mov','m4v','dat','mkv','avi','vob');// 设置附件上传类型

$upload->rootPath = './Application/Home/Public/vedio/'; // 设置附件上传根目录

$upload->savePath = ''; // 设置附件上传(子)目录

// 上传文件

$info = $upload->upload();

if(!$info) {// 上传错误提示错误信息

$error = $upload->getError();

echo $error;exit;

}

// 测试上传本地视频

function testUploadLocalVideo($accessKeyId, $accessKeySecret, $filePath)

{

require_once dirname(__DIR__) . DIRECTORY_SEPARATOR .'Controller/'. 'voduploadsdk' . DIRECTORY_SEPARATOR . 'Autoloader.php';

date_default_timezone_set('PRC');

try {

$uploader = new \AliyunVodUploader($accessKeyId, $accessKeySecret);

$uploadVideoRequest = new \UploadVideoRequest($filePath, 'testUploadLocalVideo via PHP-SDK');

 

$userData = array(

"MessageCallback"=>array("CallbackURL"=>"https://demo.sample.com/ProcessMessageCallback"),

"Extend"=>array("localId"=>"xxx", "test"=>"www")

);

$uploadVideoRequest->setUserData(json_encode($userData));

$res = $uploader->uploadLocalVideo($uploadVideoRequest);

return $res;

} catch (Exception $e) {

printf("testUploadLocalVideo Failed, ErrorMessage: %s\n Location: %s %s\n Trace: %s\n",

$e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString());

}

}

#### 执行测试代码 ####

$accessKeyId = '';

$accessKeySecret = '';

$savename = rename($info['myFile']['savename'],time());

$localFilePath = './Application/Home/Public/vedio/'.$info['myFile']['savename'];

//$localFilePath = $_FILES['file'];

//print_r($localFilePath);exit;

testUploadLocalVideo($accessKeyId, $accessKeySecret, $localFilePath);

 

}

删除

include_once 'voduploadsdk/aliyun-php-sdk-core/Config.php';

function deleteVideos($client, $videoIds) {

$request = new vod\DeleteVideoRequest();

$request->setVideoIds($videoIds); // 支持批量删除视频;videoIds为传入的视频ID列表,多个用逗号分隔

$request->setAcceptFormat('JSON');

return $client->getAcsResponse($request);

}

function initVodClient($accessKeyId, $accessKeySecret) {

$regionId = 'cn-shanghai'; // 点播服务接入区域

$profile = \DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);

return new \DefaultAcsClient($profile);

}

try {

$client = initVodClient('id', 'key');//点播的ID和key

$delInfo = deleteVideos($client,$savename);//savename视频的id

if(!empty($delInfo)){

$msg = true;

}

} catch (\Exception $e) {

print $e->getMessage()."\n";

}

下载

include_once 'voduploadsdk/aliyun-php-sdk-core/Config.php';

function getMezzanineInfo($client, $videoId) {

$request = new vod\GetMezzanineInfoRequest();

$request->setVideoId($videoId);

$request->setAuthTimeout(3600*5); // 原片下载地址过期时间,单位:秒,默认为3600秒

$request->setAcceptFormat('JSON');

 

return $client->getAcsResponse($request);

}

function initVodClient($accessKeyId, $accessKeySecret) {

$regionId = 'cn-shanghai'; // 点播服务接入区域

$profile = \DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);

return new \DefaultAcsClient($profile);

}

 

try {

$id = $_POST['id'];//视频id

if(empty($id)){

echo '参数传输失败';exit;

}

$table = M('vediow');

$savename = $table->where(['id'=>$id])->getField('savename');

$client = initVodClient('id', 'key');

$mezzanine = getMezzanineInfo($client, $savename);

$arr = (array)$mezzanine;

$url = (array)$arr['Mezzanine'];

redirect($url['FileURL']);

} catch (\Exception $e) {

print $e->getMessage()."\n";

}

 

posted @ 2020-07-07 15:20  Smile☆  阅读(1759)  评论(0编辑  收藏  举报