|
1 | 1 | <script lang="ts"> |
2 | | - import '../../../../node_modules/video.js/dist/video-js.min.css'; |
3 | | - import videojs from 'video.js'; |
4 | | - // import 'videojs-youtube'; |
5 | | - import '@codingcatdev/videojs-codingcatdev-youtube'; |
6 | | - import { onMount, onDestroy, afterUpdate, beforeUpdate } from 'svelte'; |
| 2 | + export let src: string; |
| 3 | + export let title: string; |
7 | 4 |
|
8 | | - /** |
9 | | - * See https://videojs.com/guides/options/#sources |
10 | | - * @type */ |
11 | | - export let sources: [ |
12 | | - { |
13 | | - src: string; |
14 | | - type: string; |
15 | | - } |
16 | | - ]; |
17 | | -
|
18 | | - let player: any; |
19 | | -
|
20 | | - const setPlayer = () => { |
21 | | - player = videojs( |
22 | | - 'video-player', |
23 | | - { |
24 | | - controls: true, |
25 | | - autoplay: false, |
26 | | - preload: 'auto', |
27 | | - fluid: true, |
28 | | - restoreEl: true, |
29 | | - plugins: { |
30 | | - codingcatdevYoutube: {} |
31 | | - }, |
32 | | - techOrder: ['youtube'], |
33 | | - sources |
34 | | - }, |
35 | | - undefined |
36 | | - ); |
37 | | - player.codingcatdevYoutube(); |
38 | | - player.ready(() => { |
39 | | - console.debug('videojs:player:ready'); |
40 | | - }); |
41 | | - }; |
42 | | -
|
43 | | - onMount(() => { |
44 | | - console.debug('onMount'); |
45 | | - setPlayer(); |
46 | | - console.debug('onMount:videojs:player', player); |
47 | | - }); |
48 | | - onDestroy(() => { |
49 | | - console.debug('onDestroy'); |
50 | | -
|
51 | | - for (const p of videojs.getAllPlayers()) { |
52 | | - p.dispose(); |
53 | | - } |
54 | | - }); |
55 | | - beforeUpdate(() => { |
56 | | - console.debug('beforeUpdate'); |
57 | | - }); |
58 | | - afterUpdate(() => { |
59 | | - console.debug('afterUpdate'); |
60 | | - if (player && !player.isDisposed()) { |
61 | | - player.dispose(); |
62 | | - } |
63 | | - setPlayer(); |
64 | | - console.debug('afterUpdate:videojs:player', player); |
65 | | - }); |
| 5 | + $: finalSrc = `https://www.youtube.com/embed/${src.split('/').at(-1)}`; |
66 | 6 | </script> |
67 | 7 |
|
68 | | -<svelte:head> |
69 | | - <script> |
70 | | - //This is a fake script tag because YT API needs one to append after. |
71 | | - //https:\/\/www.youtube.com\/s\/player\/e5f6cbd5\/www-widgetapi.vflset\/www-widgetapi.js |
72 | | - //This line var b = document.getElementsByTagName("script")[0];b.parentNode.insertBefore(a, b) |
73 | | - </script> |
74 | | -</svelte:head> |
75 | | - |
76 | | -<!-- svelte-ignore a11y-media-has-caption --> |
77 | | -<!-- <video bind:this={vid} /> --> |
78 | | -<video id="video-player" class="video-js"> |
79 | | - <p class="vjs-no-js"> |
80 | | - To view this video please enable JavaScript, and consider upgrading to a web browser that |
81 | | - <a href="https://videojs.com/html5-video-support/" target="_blank" rel="noreferrer" |
82 | | - >supports HTML5 video</a |
83 | | - > |
84 | | - </p> |
85 | | -</video> |
| 8 | +<div class="aspect-video"> |
| 9 | + <iframe |
| 10 | + src={finalSrc} |
| 11 | + {title} |
| 12 | + frameborder="0" |
| 13 | + allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" |
| 14 | + allowfullscreen |
| 15 | + class="w-full h-full" |
| 16 | + /> |
| 17 | +</div> |
0 commit comments