Skip to content

Commit

Permalink
MED-100: Force mimetype for m3u8
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Alexander Scholz committed May 17, 2024
1 parent 43837b5 commit c0a68dd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
7 changes: 6 additions & 1 deletion source/streamio/classes/form/edit_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public function definition_after_data() {
$resource = new media_resource($record);

$videourl = $resource->video_url($OUTPUT);
if (substr($videourl, -5) == '.m3u8') {
$type = 'video/x-mpegURL';
} else {
$type = resourcelib_guess_url_mimetype($videourl);
}
$content = [
'poster' => $resource->image_url($OUTPUT),
'elementid' => 'video-' . uniqid(),
Expand All @@ -107,7 +112,7 @@ public function definition_after_data() {
'autoplay' => false,
'option_loop' => false,
'muted' => true,
'type' => resourcelib_guess_url_mimetype($videourl),
'type' => $type,
]),
];
$mform->insertElementBefore(
Expand Down
7 changes: 6 additions & 1 deletion source/streamio/classes/output/media_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public function export_for_template(renderer_base $output) {
global $DB, $USER;
$context = \context_system::instance();
$videourl = $this->video_url($output);
if (substr($videourl, -5) == '.m3u8') {
$type = 'video/x-mpegURL';
} else {
$type = resourcelib_guess_url_mimetype($videourl);
}

$content = [
'elementid' => 'video-' . uniqid(),
Expand All @@ -74,7 +79,7 @@ public function export_for_template(renderer_base $output) {
'autoplay' => false,
'option_loop' => false,
'muted' => true,
'type' => resourcelib_guess_url_mimetype($videourl),
'type' => $type,
]),
'poster' => $this->image_url($output),
];
Expand Down
3 changes: 2 additions & 1 deletion source/streamio/templates/video.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
id="{{ elementid }}"
controls
class="video-js"
poster="https://{{ screenshot.normal }}"
poster="{{ poster }}"
>
</video>
</p>
Expand All @@ -48,6 +48,7 @@
return true;
};
var v = new VideoTime('{{ elementid }}', 0, 0, 0, {{{instance}}});
console.log(['{{ elementid }}', 0, 0, 0, {{{instance}}}]);
v.initialize();
});
{{/js}}
7 changes: 6 additions & 1 deletion source/videotime/classes/form/edit_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ public function definition_after_data() {
$resource = new media_resource($record);

$videourl = $resource->video_url($OUTPUT);
if (substr($videourl, -5) == '.m3u8') {
$type = 'video/x-mpegURL';
} else {
$type = resourcelib_guess_url_mimetype($videourl);
}

$content = [
'poster' => $resource->image_url($OUTPUT),
Expand All @@ -150,7 +155,7 @@ public function definition_after_data() {
'autoplay' => false,
'option_loop' => false,
'muted' => true,
'type' => resourcelib_guess_url_mimetype($videourl),
'type' => $type,
]),
];
$mform->insertElementBefore(
Expand Down
7 changes: 6 additions & 1 deletion source/videotime/classes/output/media_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public function __construct(stdClass $record) {
public function export_for_template(renderer_base $output) {
global $DB, $USER;
$videourl = $this->video_url($output);
if (substr($videourl, -5) == '.m3u8') {
$type = 'video/x-mpegURL';
} else {
$type = resourcelib_guess_url_mimetype($videourl);
}

$content = [
'elementid' => 'video-' . uniqid(),
Expand All @@ -82,7 +87,7 @@ public function export_for_template(renderer_base $output) {
'muted' => true,
'option_loop' => false,
'responsive' => true,
'type' => resourcelib_guess_url_mimetype($videourl),
'type' => $type,
'vimeo_url' => $videourl,
]),
'poster' => $this->image_url($output),
Expand Down

0 comments on commit c0a68dd

Please sign in to comment.