YouTube links werkend

This commit is contained in:
2020-03-24 14:42:44 +01:00
parent 843e66be6a
commit 821e0687eb
2 changed files with 12 additions and 3 deletions

View File

@@ -62,9 +62,7 @@
@if($item->video) @if($item->video)
@include('widgets/mediaplayer') @include('widgets/mediaplayer')
<video controls> @php(createVideoElement($item->video))
<source src="{!!$item->video!!}" type="application/x-mpegurl" />
</video>
@endif @endif
@if($item->source && $item->source->show) @if($item->source && $item->source->show)

View File

@@ -2,6 +2,17 @@
if(!isset($MEDIAPLAYER_INCLUDED)): if(!isset($MEDIAPLAYER_INCLUDED)):
// Make sure mediaplayer JS is not applied more than once on a page. // Make sure mediaplayer JS is not applied more than once on a page.
View::share('MEDIAPLAYER_INCLUDED', true); View::share('MEDIAPLAYER_INCLUDED', true);
function createVideoElement($url) {
$type = "application/x-mpegurl";
if(strpos($url, "youtube.com") !== false) { $type = "video/youtube"; }
if(strpos($url, "youtu.be") !== false) { $type = "video/youtube"; }
?>
<video controls>
<source src="{!!$url!!}" type="{!!$type!!}" />
</video>
<?php
}
?> ?>
@push('scripts') @push('scripts')
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/mediaelement/4.2.16/mediaelement-and-player.min.js"></script> <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/mediaelement/4.2.16/mediaelement-and-player.min.js"></script>