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

KS: 41633: Video Player not working #8310

Open
wants to merge 7 commits into
base: release_10
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\UI\Implementation\Component\Player;

use ILIAS\UI\Implementation\Render\AbstractComponentRenderer;
Expand Down Expand Up @@ -45,9 +45,6 @@ public function renderAudio(Component\Component $component, RendererInterface $d
{
$tpl = $this->getTemplate("tpl.audio.html", true, true);

$component = $component->withAdditionalOnLoadCode(function ($id) {
return "$('#$id').mediaelementplayer({stretching: 'responsive'});";
});
$id = $this->bindJavaScript($component);

if ($component->getTranscription() != "") {
Expand Down Expand Up @@ -75,11 +72,60 @@ public function renderVideo(
Component\Component $component,
RendererInterface $default_renderer
): string {
if ($this->isVimeo($component)) {
return $this->renderVimeo(
$component,
$default_renderer
);
} elseif ($this->isYoutube($component)) {
return $this->renderYoutube(
$component,
$default_renderer
);
}
return $this->renderNative(
$component,
$default_renderer
);
}

public function renderVimeo(
Component\Component $component,
RendererInterface $default_renderer
): string {

$tpl = $this->getTemplate("tpl.video_vimeo.html", true, true);

$id = $this->bindJavaScript($component);

$tpl->setVariable("ID", $id);
$tpl->setVariable("SOURCE", $component->getSource());

return $tpl->get();
}

public function renderYoutube(
Component\Component $component,
RendererInterface $default_renderer
): string {

$tpl = $this->getTemplate("tpl.video_youtube.html", true, true);

$id = $this->bindJavaScript($component);

$tpl->setVariable("ID", $id);
$tpl->setVariable("SOURCE", $component->getSource());

return $tpl->get();
}

public function renderNative(
Component\Component $component,
RendererInterface $default_renderer
): string {

$tpl = $this->getTemplate("tpl.video.html", true, true);

$component = $component->withAdditionalOnLoadCode(function ($id) {
return "$('#$id').mediaelementplayer();";
});
$id = $this->bindJavaScript($component);

foreach ($component->getSubtitleFiles() as $lang_key => $file) {
Expand All @@ -101,11 +147,21 @@ public function renderVideo(
return $tpl->get();
}

public function registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry): void
{
parent::registerResources($registry);
$registry->register('./assets/js/mediaelement-and-player.min.js');
$registry->register('./assets/css/mediaelementplayer.min.css');
$registry->register('./assets/js/vimeo.min.js');
protected function isVimeo(
Component\Component $component
): bool {
if (is_int(strpos($component->getSource(), 'vimeo.com'))) {
return true;
}
return false;
}

protected function isYoutube(
Component\Component $component
): bool {
if (is_int(strpos($component->getSource(), 'youtube.com'))) {
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function video_vimeo(): string
$renderer = $DIC->ui()->renderer();
$f = $DIC->ui()->factory();

$video = $f->player()->video("https://vimeo.com/669475821?controls=0");
$video = $f->player()->video("https://player.vimeo.com/video/669475821");

return $renderer->render($video);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function video_youtube(): string
$renderer = $DIC->ui()->renderer();
$f = $DIC->ui()->factory();

$video = $f->player()->video("https://www.youtube.com/watch?v=YSN2osYbshQ");
$video = $f->player()->video("https://www.youtube.com/embed/YSN2osYbshQ");

return $renderer->render($video);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="il-audio-container">
<audio class="il-audio-player" id="{ID}" src="{SOURCE}" preload="metadata"></audio>
<audio controls="controls" class="il-audio-player" id="{ID}" src="{SOURCE}" preload="metadata"></audio>
<!-- BEGIN transcription -->
{BUTTON_AND_MODAL}
<!-- END transcription -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="il-video-container">
<video class="il-video-player" id="{ID}" src="{SOURCE}" style="max-width: 100%;" preload="metadata" <!-- BEGIN poster -->poster="{POSTER_SOURCE}"<!-- END poster -->>
<video controls="controls" class="il-video-player" id="{ID}" src="{SOURCE}" preload="metadata" <!-- BEGIN poster -->poster="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" style="background-image:url('{POSTER_SOURCE}')"<!-- END poster -->>
<!-- BEGIN track --><track kind="subtitles" src="{TRACK_SOURCE}" srclang="{TRACK_LANG}" /><!-- END track -->
</video>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="il-video-container">
<iframe id="{ID}" src="{SOURCE}" allow="fullscreen; autoplay; picture-in-picture;" referrerpolicy="strict-origin-when-cross-origin"></iframe>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="il-video-container">
<iframe id="{ID}" src="{SOURCE}" allow="fullscreen; autoplay; picture-in-picture;" referrerpolicy="strict-origin-when-cross-origin"></iframe>
</div>
3 changes: 2 additions & 1 deletion components/ILIAS/UI/tests/Component/Item/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,12 @@ public function testRenderAudioPlayer(): void
$c = $f->standard("title")->withAudioPlayer($audio);

$html = $r->render($c);

$expected = <<<EOT
<div class="il-item il-std-item ">
<h4 class="il-item-title">title</h4>
<div class="il-item-audio"><div class="il-audio-container">
<audio class="il-audio-player" id="id_1" src="src" preload="metadata"></audio>
<audio controls="controls" class="il-audio-player" id="" src="src" preload="metadata"></audio>
</div></div>
</div>
EOT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function testRenderAudio(): void

$expected = <<<EOT
<div class="il-audio-container">
<audio class="il-audio-player" id="id_1" src="/foo" preload="metadata"></audio>
<audio controls="controls" class="il-audio-player" id="" src="/foo" preload="metadata"></audio>
</div>
EOT;
$this->assertHTMLEquals(
Expand Down
47 changes: 43 additions & 4 deletions components/ILIAS/UI/tests/Component/Player/PlayerVideoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function testRenderVideo(): void
$html = $r->render($video);
$expected = <<<EOT
<div class="il-video-container">
<video class="il-video-player" id="id_1" src="/foo" style="max-width: 100%;" preload="metadata" >
<video controls="controls" class="il-video-player" id="" src="/foo" preload="metadata" >
</video>
</div>
EOT;
Expand All @@ -126,10 +126,9 @@ public function testRenderWithPoster(): void
$video = $f->video("/foo")->withPoster("bar.jpg");

$html = $r->render($video);

$expected = <<<EOT
<div class="il-video-container">
<video class="il-video-player" id="id_1" src="/foo" style="max-width: 100%;" preload="metadata" poster="bar.jpg">
<video controls="controls" class="il-video-player" id="" src="/foo" preload="metadata" poster="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" style="background-image:url('bar.jpg')">
</video>
</div>
EOT;
Expand All @@ -149,10 +148,50 @@ public function testRenderWithSubtitles(): void
$html = $r->render($video);
$expected = <<<EOT
<div class="il-video-container">
<video class="il-video-player" id="id_1" src="/foo" style="max-width: 100%;" preload="metadata" >
<video controls="controls" class="il-video-player" id="" src="/foo" preload="metadata" >
<track kind="subtitles" src="subtitles.vtt" srclang="en" />
</video>
</div>
EOT;
$this->assertHTMLEquals(
$this->brutallyTrimHTML($expected),
$this->brutallyTrimHTML($html)
);
}

public function testRenderYoutube(): void
{
$f = $this->getFactory();
$r = $this->getDefaultRenderer();

$video = $f->video("https://www.youtube.com/embed/YSN2osYbshQ");

$html = $r->render($video);

$expected = <<<EOT
<div class="il-video-container">
<iframe id="" src="https://www.youtube.com/embed/YSN2osYbshQ" allow="fullscreen; autoplay; picture-in-picture;" referrerpolicy="strict-origin-when-cross-origin"></iframe>
</div>
EOT;
$this->assertHTMLEquals(
$this->brutallyTrimHTML($expected),
$this->brutallyTrimHTML($html)
);
}

public function testRenderVimeo(): void
{
$f = $this->getFactory();
$r = $this->getDefaultRenderer();

$video = $f->video("https://player.vimeo.com/video/669475821");

$html = $r->render($video);

$expected = <<<EOT
<div class="il-video-container">
<iframe id="" src="https://player.vimeo.com/video/669475821" allow="fullscreen; autoplay; picture-in-picture;" referrerpolicy="strict-origin-when-cross-origin"></iframe>
</div>
EOT;
$this->assertHTMLEquals(
$this->brutallyTrimHTML($expected),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

//== Player
$il-player-audio-width: 100%;
$il-player-audio-height: 30px;

// audio
.il-audio-container {
Expand All @@ -10,5 +11,20 @@ $il-player-audio-width: 100%;
}
}
.il-audio-player {
background: $il-neutral-color;
background: transparent;
height: $il-player-audio-height;
width: $il-player-audio-width;
}
.il-video-container {
video {
background-position: center;
background-size: contain;
background-repeat: no-repeat;
width:100%;
}
iframe {
width:100%;
aspect-ratio: 16/9;
border:0;
}
}
16 changes: 15 additions & 1 deletion templates/default/delos.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading