fix: ios player
This commit is contained in:
@@ -82,7 +82,6 @@ func (c *Controller) MediaIndex(ctx fiber.Ctx) error {
|
|||||||
if claim == nil {
|
if claim == nil {
|
||||||
return errorx.RequestUnAuthorized
|
return errorx.RequestUnAuthorized
|
||||||
}
|
}
|
||||||
|
|
||||||
// c.Locals(consts.CtxKeyJwt, token)
|
// c.Locals(consts.CtxKeyJwt, token)
|
||||||
token := fiber.Locals[string](ctx, consts.CtxKeyJwt)
|
token := fiber.Locals[string](ctx, consts.CtxKeyJwt)
|
||||||
model, err := c.svc.GetMediaByHash(ctx.Context(), claim.TenantID, hash)
|
model, err := c.svc.GetMediaByHash(ctx.Context(), claim.TenantID, hash)
|
||||||
@@ -103,6 +102,7 @@ func (c *Controller) MediaIndex(ctx fiber.Ctx) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.Set("Content-Type", "application/vnd.apple.mpegurl")
|
||||||
return ctx.SendString(playlist.String())
|
return ctx.SendString(playlist.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,6 +133,7 @@ func (c *Controller) MediaSegment(ctx fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filepath := c.svc.GetSegmentPath(ctx.Context(), mediaType, model.TenantID, model.Hash, segments[0])
|
filepath := c.svc.GetSegmentPath(ctx.Context(), mediaType, model.TenantID, model.Hash, segments[0])
|
||||||
|
ctx.Set("Content-Type", "video/mp2t")
|
||||||
return ctx.SendFile(filepath)
|
return ctx.SendFile(filepath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
35
frontend/package-lock.json
generated
35
frontend/package-lock.json
generated
@@ -9,6 +9,7 @@
|
|||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.7.9",
|
"axios": "^1.7.9",
|
||||||
|
"dplayer": "^1.27.1",
|
||||||
"hls.js": "^0.8.5",
|
"hls.js": "^0.8.5",
|
||||||
"pinia": "^2.2.6",
|
"pinia": "^2.2.6",
|
||||||
"vant": "^4.9.9",
|
"vant": "^4.9.9",
|
||||||
@@ -871,6 +872,12 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/balloon-css": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://npm.hub.ipao.vip/repository/npm/balloon-css/-/balloon-css-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-urXwkHgwp6GsXVF+it01485Z2Cj4pnW02ICnM0TemOlkKmCNnDLmyy+ZZiRXBpwldUXO+aRNr7Hdia4CBvXJ5A==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/binary-extensions": {
|
"node_modules/binary-extensions": {
|
||||||
"version": "2.3.0",
|
"version": "2.3.0",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
@@ -1108,6 +1115,28 @@
|
|||||||
"node": ">=0.4.0"
|
"node": ">=0.4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/dplayer": {
|
||||||
|
"version": "1.27.1",
|
||||||
|
"resolved": "https://npm.hub.ipao.vip/repository/npm/dplayer/-/dplayer-1.27.1.tgz",
|
||||||
|
"integrity": "sha512-2laBMXs5V1B9zPwJ7eAIw/OBo+Xjvy03i4GHTk3Cg+IWbrq8rKMFO0fFr6ClAYotYOCcFGOvaJDkOZcgKllsCA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"axios": "1.2.3",
|
||||||
|
"balloon-css": "^1.0.3",
|
||||||
|
"promise-polyfill": "8.3.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/dplayer/node_modules/axios": {
|
||||||
|
"version": "1.2.3",
|
||||||
|
"resolved": "https://npm.hub.ipao.vip/repository/npm/axios/-/axios-1.2.3.tgz",
|
||||||
|
"integrity": "sha512-pdDkMYJeuXLZ6Xj/Q5J3Phpe+jbGdsSzlQaFVkMQzRUL05+6+tetX8TV3p4HrU4kzuO9bt+io/yGQxuyxA/xcw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"follow-redirects": "^1.15.0",
|
||||||
|
"form-data": "^4.0.0",
|
||||||
|
"proxy-from-env": "^1.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/electron-to-chromium": {
|
"node_modules/electron-to-chromium": {
|
||||||
"version": "1.5.66",
|
"version": "1.5.66",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
@@ -1997,6 +2026,12 @@
|
|||||||
"node": "^10 || ^12 || >=14"
|
"node": "^10 || ^12 || >=14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/promise-polyfill": {
|
||||||
|
"version": "8.3.0",
|
||||||
|
"resolved": "https://npm.hub.ipao.vip/repository/npm/promise-polyfill/-/promise-polyfill-8.3.0.tgz",
|
||||||
|
"integrity": "sha512-H5oELycFml5yto/atYqmjyigJoAo3+OXwolYiH7OfQuYlAqhxNvTfiNMbV9hsC6Yp83yE5r2KTVmtrG6R9i6Pg==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/proxy-from-env": {
|
"node_modules/proxy-from-env": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://npm.hub.ipao.vip/repository/npm/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
"resolved": "https://npm.hub.ipao.vip/repository/npm/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
||||||
|
|||||||
@@ -4,12 +4,13 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite --host 0.0.0.0",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.7.9",
|
"axios": "^1.7.9",
|
||||||
|
"dplayer": "^1.27.1",
|
||||||
"hls.js": "^0.8.5",
|
"hls.js": "^0.8.5",
|
||||||
"pinia": "^2.2.6",
|
"pinia": "^2.2.6",
|
||||||
"vant": "^4.9.9",
|
"vant": "^4.9.9",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<van-nav-bar :title="item.title" left-text="返回" left-arrow @click-left="onClickLeft" />
|
<van-nav-bar :title="item.title" left-text="返回" left-arrow @click-left="onClickLeft" />
|
||||||
<video controls id="video" :poster="item.poster" />
|
<!-- <video controls id="video" :poster="item.poster" /> -->
|
||||||
|
<div id="dplayer" :style="{ backgroundImage: `url(${item.poster})` }"></div>
|
||||||
|
|
||||||
<template v-if="false === item.bought">
|
<template v-if="false === item.bought">
|
||||||
<van-notice-bar left-icon="volume-o" text="未购买的视频、音频默认播放时长为1分钟左右。" />
|
<van-notice-bar left-icon="volume-o" text="未购买的视频、音频默认播放时长为1分钟左右。" />
|
||||||
@@ -26,32 +27,106 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import request from "@/utils/request";
|
import request from "@/utils/request";
|
||||||
|
import DPlayer from "dplayer";
|
||||||
import Hls from "hls.js";
|
import Hls from "hls.js";
|
||||||
import { onBeforeUnmount, onMounted } from "vue";
|
import { onBeforeUnmount, onMounted } from "vue";
|
||||||
|
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const pageLoading = ref(true)
|
const pageLoading = ref(true)
|
||||||
|
|
||||||
|
let player = null;
|
||||||
|
|
||||||
const item = ref({
|
const item = ref({
|
||||||
title: "加载中...",
|
title: "加载中...",
|
||||||
});
|
});
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
const player = document.getElementById("video");
|
player?.destroy();
|
||||||
if (player) {
|
|
||||||
player.pause();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadMedia(route.params.hash);
|
loadMedia(route.params.hash);
|
||||||
const player = document.getElementById("video");
|
|
||||||
player.addEventListener("ended", function () {
|
|
||||||
console.log("Video ended");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const onClickLeft = () => {
|
||||||
|
if (route.meta.from?.name) {
|
||||||
|
router.back();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
router.replace({
|
||||||
|
name: "tab.home",
|
||||||
|
params: {
|
||||||
|
tenant: route.params.tenant,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const loadMedia = (hash) => {
|
||||||
|
request
|
||||||
|
.get(`/medias/${hash}`)
|
||||||
|
.then((res) => {
|
||||||
|
console.log(res);
|
||||||
|
item.value = res.data;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error("ERROR", err);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
pageLoading.value = false
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const play = (hash, type) => {
|
||||||
|
let source = `/v1/medias/${hash}/${type}`;
|
||||||
|
if (navigator.userAgent.indexOf("iPhone") > -1) {
|
||||||
|
source = `/v1/medias/${hash}/${type}?token=${__GA}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
player = new DPlayer({
|
||||||
|
container: document.getElementById('dplayer'),
|
||||||
|
video: {
|
||||||
|
url: source,
|
||||||
|
pic: item.value.poster,
|
||||||
|
type: 'customHls',
|
||||||
|
customType: {
|
||||||
|
customHls: function (video, player) {
|
||||||
|
const hls = new Hls({
|
||||||
|
xhrSetup: function (xhr, url) {
|
||||||
|
xhr.withCredentials = true;
|
||||||
|
xhr.setRequestHeader("Authorization", "Bearer " + __GA);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
hls.loadSource(source);
|
||||||
|
hls.attachMedia(video);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
player.play();
|
||||||
|
|
||||||
|
// if (Hls.isSupported()) {
|
||||||
|
// var hls = new Hls({
|
||||||
|
// xhrSetup: function (xhr, url) {
|
||||||
|
// xhr.withCredentials = true;
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
// hls.loadSource(source);
|
||||||
|
// hls.attachMedia(player);
|
||||||
|
// hls.on(Hls.Events.MANIFEST_PARSED, function () {
|
||||||
|
// player.play();
|
||||||
|
// });
|
||||||
|
// } else if (player.canPlayType("application/vnd.apple.mpegurl")) {
|
||||||
|
// player.src = source;
|
||||||
|
// player.addEventListener("loadedmetadata", function () {
|
||||||
|
// player.play();
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const buy = () => {
|
const buy = () => {
|
||||||
// get use balance
|
// get use balance
|
||||||
request
|
request
|
||||||
@@ -99,55 +174,6 @@ const buy = () => {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onClickLeft = () => {
|
|
||||||
if (route.meta.from?.name) {
|
|
||||||
router.back();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
router.replace({
|
|
||||||
name: "tab.home",
|
|
||||||
params: {
|
|
||||||
tenant: route.params.tenant,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const loadMedia = (hash) => {
|
|
||||||
request
|
|
||||||
.get(`/medias/${hash}`)
|
|
||||||
.then((res) => {
|
|
||||||
console.log(res);
|
|
||||||
item.value = res.data;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error("ERROR", err);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
pageLoading.value = false
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const play = (hash, type) => {
|
|
||||||
const player = document.getElementById("video");
|
|
||||||
const source = `/v1/medias/${hash}/${type}?token=${__GA}`;
|
|
||||||
if (Hls.isSupported()) {
|
|
||||||
var hls = new Hls({
|
|
||||||
xhrSetup: function (xhr, url) {
|
|
||||||
xhr.withCredentials = true;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
hls.loadSource(source);
|
|
||||||
hls.attachMedia(player);
|
|
||||||
hls.on(Hls.Events.MANIFEST_PARSED, function () {
|
|
||||||
player.play();
|
|
||||||
});
|
|
||||||
} else if (player.canPlayType("application/vnd.apple.mpegurl")) {
|
|
||||||
player.src = source;
|
|
||||||
player.addEventListener("loadedmetadata", function () {
|
|
||||||
player.play();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -155,10 +181,13 @@ const play = (hash, type) => {
|
|||||||
padding: 1em;
|
padding: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#video {
|
#video,
|
||||||
|
#dplayer {
|
||||||
background-color: #cccccc;
|
background-color: #cccccc;
|
||||||
aspect-ratio: 16 / 9;
|
aspect-ratio: 16 / 9;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
object-fit: fill;
|
object-fit: fill;
|
||||||
|
background-size: cover;
|
||||||
|
background-position: center;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { defineConfig } from "vite";
|
|||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
server: {
|
server: {
|
||||||
proxy: {
|
proxy: {
|
||||||
'^/static': {
|
'^/poster': {
|
||||||
target: 'http://localhost:9600',
|
target: 'http://localhost:9600',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
// rewrite: (path) => path.replace(/^\/api/, '')
|
// rewrite: (path) => path.replace(/^\/api/, '')
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
"settings": {
|
"settings": {
|
||||||
"vue3snippets.enable-compile-vue-file-on-did-save-code": false,
|
"vue3snippets.enable-compile-vue-file-on-did-save-code": false,
|
||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
|
"dplayer",
|
||||||
"qvyun"
|
"qvyun"
|
||||||
],
|
],
|
||||||
"git.ignoreLimitWarning": true
|
"git.ignoreLimitWarning": true
|
||||||
|
|||||||
Reference in New Issue
Block a user