Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TTK-27298: Play hls videos #163

Merged
merged 6 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php-versions: ['7.4']
php-versions: ['8.2']

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Conf/conf.json.twig
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
]
},
"es.upv.paella.hlsVideoFormat": {
"enabled": {{ isLive ? 'true' : 'false' }},
"enabled": true,
"order": 0,
"hlsConfig": {
"maxBufferLength": 40
Expand Down
22 changes: 21 additions & 1 deletion Services/StreamsManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Pumukit\BaseLivePlayerBundle\Services\LiveService;
use Pumukit\BasePlayerBundle\Services\TrackUrlService;
use Pumukit\SchemaBundle\Document\MediaType\Track;
use Pumukit\SchemaBundle\Document\MultimediaObject;
use Pumukit\SchemaBundle\Services\PicService;
use Symfony\Component\Mime\MimeTypes;
Expand Down Expand Up @@ -42,7 +43,7 @@ public function createStreamsForVoD(MultimediaObject $multimediaObject, ?string
$data['streams'] = [];

if (!$multimediaObject->isMultistream()) {
$track = $multimediaObject->getTrackById($trackId) ?? $multimediaObject->getDisplayTrack();
$track = $multimediaObject->getTrackById($trackId) ?? $this->searchPriorityTrack($multimediaObject);
if ($track) {
$dataStream = $this->buildDataStream([$track]);
$dataStream['content'] = 'presenter';
Expand Down Expand Up @@ -133,6 +134,20 @@ public function buildDataLive(array $urls, string $mimeType): array
return $dataStream;
}

public function searchPriorityTrack(MultimediaObject $multimediaObject): Track
{
$displayTracks = $multimediaObject->getTracksWithTag('display');
if (count($displayTracks) >= 2) {
foreach ($displayTracks as $track) {
if (str_ends_with($track->storage()->path()->path(), '.m3u8')) {
return $track;
}
}
}

return $multimediaObject->getDisplayTrack();
}

private function getMmobjTracks(MultimediaObject $multimediaObject, ?string $trackId): array
{
$tracks = [
Expand Down Expand Up @@ -193,6 +208,9 @@ private function buildDataStream(array $tracks): array
// $mimeType = $track->metadata()->mimetype();
$mimeTypes = new MimeTypes();
$mimeType = $mimeTypes->guessMimeType($track->storage()->path()->path());
if ('text/plain' === $mimeType && str_ends_with($track->storage()->path()->path(), '.m3u8')) {
$mimeType = 'video/mp4';
}
$src = $this->getAbsoluteUrl($this->trackUrlService->generateTrackFileUrl($track));

$dataStreamTrack = [
Expand All @@ -209,6 +227,8 @@ private function buildDataStream(array $tracks): array

if (in_array($format, ['mpeg', 'x-m4a']) && $track->metadata()->isOnlyAudio()) {
$format = 'audio';
} elseif (str_ends_with($track->storage()->path()->path(), '.m3u8') && 'video/mp4' === $mimeType) {
$format = 'hls';
}

if (!isset($sources[$format])) {
Expand Down
Loading