add video to mobile via YouTube
This commit is contained in:
1 parent
8e6c5e2bda
commit
c475960219
4 files changed
+68
-6
No files matched your search
@@ -1,17 +1,29 @@
|
|||||||
<template>
|
<template>
|
||||||
<Teleport to="body">
|
<Teleport to="body">
|
||||||
<video v-if="videoURL" controls :src="videoURL" ref="video">Hello</video>
|
<div :class="$style.container">
|
||||||
|
<YouTube v-if="youtubeID" :id="youtubeID" />
|
||||||
|
<video
|
||||||
|
v-else-if="videoURL"
|
||||||
|
controls
|
||||||
|
:src="videoURL"
|
||||||
|
ref="video"
|
||||||
|
@error="onVideoNotFound"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</Teleport>
|
</Teleport>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useData } from "vitepress";
|
import { useData } from "vitepress";
|
||||||
import { computed, useTemplateRef, watch } from "vue";
|
import { computed, ref, useTemplateRef, watch } from "vue";
|
||||||
|
import YouTube from "./YouTube.vue";
|
||||||
|
|
||||||
const { frontmatter } = useData<{ video?: string }>();
|
const { frontmatter } = useData<{ video?: string }>();
|
||||||
const videoURL = computed(() => frontmatter.value?.video);
|
const videoURL = computed(() => frontmatter.value?.video);
|
||||||
const videoEl = useTemplateRef("video");
|
const videoEl = useTemplateRef("video");
|
||||||
|
|
||||||
|
const youtubeID = ref("");
|
||||||
|
|
||||||
function setImgClick() {
|
function setImgClick() {
|
||||||
document.removeEventListener("click", imgClickListener);
|
document.removeEventListener("click", imgClickListener);
|
||||||
document.addEventListener("click", imgClickListener);
|
document.addEventListener("click", imgClickListener);
|
||||||
@@ -43,21 +55,30 @@ watch(videoURL, () => {
|
|||||||
setImgClick();
|
setImgClick();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function onVideoNotFound() {
|
||||||
|
const m = /\[(.+?)\]\.\S+$/.exec(videoURL.value || "") || [];
|
||||||
|
youtubeID.value = m[1] || "";
|
||||||
|
}
|
||||||
|
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
const { SSR } = import.meta.env;
|
const { SSR } = import.meta.env;
|
||||||
|
|
||||||
if (!SSR){
|
if (!SSR) {
|
||||||
setTimeout(() => setImgClick(), 500);
|
setTimeout(() => setImgClick(), 500);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style module>
|
||||||
video {
|
.container {
|
||||||
width: 400px;
|
width: 400px;
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 10px;
|
bottom: 10px;
|
||||||
left: 10px;
|
left: 10px;
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
|
|
||||||
|
> * {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<template>
|
||||||
|
<div :class="$style.container">
|
||||||
|
<iframe
|
||||||
|
:class="$style.iframe"
|
||||||
|
width="100%"
|
||||||
|
height="100%"
|
||||||
|
:src="'https://www.youtube.com/embed/' + $props.id"
|
||||||
|
frameborder="0"
|
||||||
|
allow="
|
||||||
|
accelerometer;
|
||||||
|
autoplay;
|
||||||
|
encrypted-media;
|
||||||
|
gyroscope;
|
||||||
|
picture-in-picture;
|
||||||
|
fullscreen;
|
||||||
|
"
|
||||||
|
>
|
||||||
|
</iframe>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
defineProps<{ id: string; title?: string }>();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style module>
|
||||||
|
.container {
|
||||||
|
padding-bottom: 56.25%;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.iframe {
|
||||||
|
position: absolute;
|
||||||
|
top: 0px;
|
||||||
|
left: 0px;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "tauri dev",
|
"dev": "tauri dev",
|
||||||
"android": "tauri android run",
|
"android": "tauri android run",
|
||||||
|
"android:install:debug": "adb install -r src-tauri/gen/android/app/build/outputs/apk/arm64/debug/app-arm64-debug.apk",
|
||||||
"build": "tauri build",
|
"build": "tauri build",
|
||||||
"browser": "concurrently 'pnpm:browser:*'",
|
"browser": "concurrently 'pnpm:browser:*'",
|
||||||
"browser:server": "node server.js",
|
"browser:server": "node server.js",
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
"json.validate.enable": false
|
"json.validate.enable": false,
|
||||||
|
"vue3snippets.enable-compile-vue-file-on-did-save-code": true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user