🎨Optimize video player
This commit is contained in:
parent
c50623a3ef
commit
a2d503b284
@ -13,7 +13,6 @@ import store from "@/store/index";
|
|||||||
import Clipboard from "@/plugin/clipboard";
|
import Clipboard from "@/plugin/clipboard";
|
||||||
import VueLazyload from "vue-lazyload";
|
import VueLazyload from "vue-lazyload";
|
||||||
import Viewer from "v-viewer";
|
import Viewer from "v-viewer";
|
||||||
import VuePlyr from "vue-plyr";
|
|
||||||
import cdnpath from "./libs/util.cdn";
|
import cdnpath from "./libs/util.cdn";
|
||||||
// 组件
|
// 组件
|
||||||
import "@/components";
|
import "@/components";
|
||||||
@ -32,7 +31,6 @@ Vue.use(VueLazyload, {
|
|||||||
loading: cdnpath("images/airplane.gif"),
|
loading: cdnpath("images/airplane.gif"),
|
||||||
});
|
});
|
||||||
Vue.use(Viewer);
|
Vue.use(Viewer);
|
||||||
Vue.use(VuePlyr);
|
|
||||||
|
|
||||||
new Vue({
|
new Vue({
|
||||||
router,
|
router,
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</label>
|
</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input class="input" type="text" :value="downloadUrl" />
|
<input class="input" type="text" :value="videoUrl" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="columns is-mobile is-multiline has-text-centered">
|
<div class="columns is-mobile is-multiline has-text-centered">
|
||||||
@ -78,13 +78,15 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { decode64 } from "@utils/AcrouUtil";
|
import { decode64 } from "@utils/AcrouUtil";
|
||||||
import { Hls, Flv } from "@/plugin/vplayer";
|
import VuePlyr from "vue-plyr";
|
||||||
export default {
|
export default {
|
||||||
|
comments: {
|
||||||
|
VuePlyr,
|
||||||
|
},
|
||||||
data: function() {
|
data: function() {
|
||||||
return {
|
return {
|
||||||
apiVideoUrl: "",
|
apiVideoUrl: "",
|
||||||
videoUrl: "",
|
videoUrl: "",
|
||||||
downloadUrl: "",
|
|
||||||
subtitle: "",
|
subtitle: "",
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -97,8 +99,7 @@ export default {
|
|||||||
let index = path.lastIndexOf(".");
|
let index = path.lastIndexOf(".");
|
||||||
this.suffix = path.substring(index + 1, path.length);
|
this.suffix = path.substring(index + 1, path.length);
|
||||||
this.loadSub(path, index);
|
this.loadSub(path, index);
|
||||||
this.videoUrl = path;
|
this.videoUrl = window.location.origin + path;
|
||||||
this.downloadUrl = window.location.origin + path;
|
|
||||||
this.apiVideoUrl = this.options.api + this.videoUrl;
|
this.apiVideoUrl = this.options.api + this.videoUrl;
|
||||||
if (!this.options.api) {
|
if (!this.options.api) {
|
||||||
let options = {
|
let options = {
|
||||||
@ -107,39 +108,52 @@ export default {
|
|||||||
media: this.player.media,
|
media: this.player.media,
|
||||||
};
|
};
|
||||||
if (this.suffix === "m3u8") {
|
if (this.suffix === "m3u8") {
|
||||||
Hls({
|
this.loadHls(options);
|
||||||
...options,
|
|
||||||
callback: (hls) => {
|
|
||||||
// Handle changing captions
|
|
||||||
this.player.on("languagechange", () => {
|
|
||||||
// Caption support is still flaky. See: https://github.com/sampotts/plyr/issues/994
|
|
||||||
setTimeout(
|
|
||||||
() => (hls.subtitleTrack = this.player.currentTrack),
|
|
||||||
50
|
|
||||||
);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else if (this.suffix === "flv") {
|
} else if (this.suffix === "flv") {
|
||||||
Flv(options);
|
this.loadFlv(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
loadSub(path, index) {
|
loadSub(path, index) {
|
||||||
this.subtitle = path.substring(0, index) + ".vtt";
|
this.subtitle = path.substring(0, index) + ".vtt";
|
||||||
},
|
},
|
||||||
|
loadHls(options) {
|
||||||
|
import("@/plugin/vplayer/hls").then((res) => {
|
||||||
|
var Hls = res.default;
|
||||||
|
Hls({
|
||||||
|
...options,
|
||||||
|
callback: (hls) => {
|
||||||
|
// Handle changing captions
|
||||||
|
this.player.on("languagechange", () => {
|
||||||
|
// Caption support is still flaky. See: https://github.com/sampotts/plyr/issues/994
|
||||||
|
setTimeout(
|
||||||
|
() => (hls.subtitleTrack = this.player.currentTrack),
|
||||||
|
50
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
loadFlv(options) {
|
||||||
|
import("@/plugin/vplayer/flv").then((res) => {
|
||||||
|
var Flv = res.default;
|
||||||
|
Flv(options);
|
||||||
|
});
|
||||||
|
},
|
||||||
copy() {
|
copy() {
|
||||||
this.$copyText(this.downloadUrl);
|
this.$copyText(this.videoUrl);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
options() {
|
options() {
|
||||||
var options = window.themeOptions.video;
|
var options = window.themeOptions.video;
|
||||||
return {
|
return {
|
||||||
...options,
|
autoplay: false,
|
||||||
autoplay: options.autoplay || false,
|
invertTime: false,
|
||||||
invertTime: options.invertTime || false,
|
settings: ["quality", "speed", "loop"],
|
||||||
controls: options.controls || [
|
ratio: "16:9",
|
||||||
|
controls: [
|
||||||
"play-large",
|
"play-large",
|
||||||
"restart",
|
"restart",
|
||||||
"play",
|
"play",
|
||||||
@ -155,7 +169,7 @@ export default {
|
|||||||
"download",
|
"download",
|
||||||
"fullscreen",
|
"fullscreen",
|
||||||
],
|
],
|
||||||
settings: options.settings || ["quality", "speed", "loop"],
|
...options,
|
||||||
captions: { active: true, language: "default", ...options.captions },
|
captions: { active: true, language: "default", ...options.captions },
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user