mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-07-06 08:51:10 +08:00
# Conflicts: # app/Console/Tasks/CleanLogTask.php # app/Console/Tasks/DeliverTask.php # app/Console/Tasks/NoticeTask.php # app/Http/Admin/Services/AuthNode.php # app/Http/Admin/Services/Setting.php # app/Http/Api/Services/Account.php # app/Library/Utils/Lock.php # app/Listeners/Trade.php # app/Listeners/User.php # app/Models/Course.php # app/Models/Online.php # app/Models/UserSession.php # app/Models/UserToken.php # app/Services/Auth/Api.php # app/Services/Auth/Home.php
64 lines
1.4 KiB
PHP
64 lines
1.4 KiB
PHP
<?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 [];
|
||
}
|
||
|
||
$vod = new Vod();
|
||
|
||
$result = [];
|
||
|
||
foreach ($vod->file_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;
|
||
}
|
||
|
||
/**
|
||
* 腾讯云播放器只支持[od|hd|sd],实际转码速率[hd|sd|fd],重新映射清晰度
|
||
*/
|
||
protected function getVodTemplates()
|
||
{
|
||
return [
|
||
'od' => ['height' => 720, 'rate' => 1800],
|
||
'hd' => ['height' => 540, 'rate' => 1000],
|
||
'sd' => ['height' => 360, 'rate' => 400],
|
||
];
|
||
}
|
||
|
||
}
|