1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-22 03:32:47 +08:00
2020-12-21 20:16:34 +08:00

69 lines
1.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Services;
use App\Repos\Chapter as ChapterRepo;
class ChapterVod extends Service
{
public function getPlayUrls($chapterId)
{
$chapterRepo = new ChapterRepo();
$vod = $chapterRepo->findChapterVod($chapterId);
if (empty($vod->file_transcode)) {
return [];
}
/**
* @var array $transcode
*/
$transcode = $vod->file_transcode;
$vod = new Vod();
$result = [];
foreach ($transcode as $key => $file) {
$file['url'] = $vod->getPlayUrl($file['url']);
$type = $this->getDefinitionType($file['height']);
$result[$type] = $file;
}
return $result;
}
protected function getDefinitionType($height)
{
$default = 'od';
$vodTemplates = $this->getVodTemplates();
/**
* 腾讯云播放器只支持[od|hd|sd]遇到fd替换为od
*/
foreach ($vodTemplates as $key => $template) {
if ($height >= $template['height']) {
return $key == 'fd' ? $default : $key;
}
}
return $default;
}
/**
* @return array
*/
protected function getVodTemplates()
{
return [
'hd' => ['height' => 720, 'rate' => 1800],
'sd' => ['height' => 540, 'rate' => 1000],
'fd' => ['height' => 360, 'rate' => 400],
];
}
}