|
@@ -0,0 +1,215 @@
|
|
|
+<template>
|
|
|
+ <div class="player-box">
|
|
|
+ <div :id="state.id" class="playWnd"></div>
|
|
|
+ <div v-show="state.isLoading" class="loader"></div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup>
|
|
|
+import { reactive, onMounted, onActivated, nextTick, onBeforeUnmount } from 'vue';
|
|
|
+
|
|
|
+const play = async (url) => {
|
|
|
+ state.wsUrl = url;
|
|
|
+ realplay(url);
|
|
|
+};
|
|
|
+
|
|
|
+const stop = async () => {
|
|
|
+ stopPlay();
|
|
|
+};
|
|
|
+
|
|
|
+const playback = async (url, startTime, endTime) => {
|
|
|
+ console.log('playback', url, state.mode, startTime, endTime);
|
|
|
+ startTime += 'Z';
|
|
|
+ endTime += 'Z';
|
|
|
+ state.player &&
|
|
|
+ state.player.JS_Play(url, { playURL: url, mode: 1 }, 0, startTime, endTime).then(
|
|
|
+ () => {
|
|
|
+ console.log('playback success 播放成功');
|
|
|
+ state.player && state.player.JS_Resize();
|
|
|
+ state.isLoading = false;
|
|
|
+ emits('onPlaying');
|
|
|
+ },
|
|
|
+ (e) => {
|
|
|
+ emits('onPlayError');
|
|
|
+ console.error('playerror', e);
|
|
|
+ }
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
+defineExpose({
|
|
|
+ play,
|
|
|
+ stop,
|
|
|
+ playback
|
|
|
+});
|
|
|
+
|
|
|
+const emits = defineEmits(['onPlaying', 'onPlayError']);
|
|
|
+
|
|
|
+const state = reactive({
|
|
|
+ id: 'playWnd' + Math.random().toString(16).slice(2),
|
|
|
+ player: null,
|
|
|
+ idWidth: 0,
|
|
|
+ idHeight: 0,
|
|
|
+ mode: 0,
|
|
|
+ isLoading: true,
|
|
|
+ wsUrl: ''
|
|
|
+});
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ nextTick(() => {
|
|
|
+ getElementWidth();
|
|
|
+ createPlayer();
|
|
|
+ });
|
|
|
+
|
|
|
+ window.addEventListener('resize', () => {
|
|
|
+ state.player && state.player.JS_Resize();
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
+onActivated(() => {
|
|
|
+ getElementWidth();
|
|
|
+});
|
|
|
+
|
|
|
+onBeforeUnmount(() => {
|
|
|
+ stopPlay();
|
|
|
+});
|
|
|
+
|
|
|
+// 获取元素宽高
|
|
|
+const getElementWidth = () => {
|
|
|
+ state.idWidth = document.getElementById(state.id)?.offsetWidth;
|
|
|
+ state.idHeight = document.getElementById(state.id)?.offsetHeight;
|
|
|
+};
|
|
|
+
|
|
|
+// 初始化播放器
|
|
|
+const createPlayer = () => {
|
|
|
+ state.player = new window.JSPlugin({
|
|
|
+ szId: state.id,
|
|
|
+ szBasePath: './',
|
|
|
+ iMaxSplit: 1,
|
|
|
+ iCurrentSplit: 1,
|
|
|
+ bSupporDoubleClickFull: false,
|
|
|
+ openDebug: false,
|
|
|
+ oStyle: {
|
|
|
+ borderSelect: '#000'
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 事件回调绑定
|
|
|
+ state.player.JS_SetWindowControlCallback({
|
|
|
+ windowEventSelect: function (iWndIndex) {
|
|
|
+ //插件选中窗口回调
|
|
|
+ console.log('windowSelect callback: ', iWndIndex);
|
|
|
+ },
|
|
|
+ pluginErrorHandler: function (iWndIndex, iErrorCode, oError) {
|
|
|
+ //插件错误回调
|
|
|
+ console.log('插件错误回调pluginError callback: ', iWndIndex, iErrorCode, oError);
|
|
|
+ setTimeout(() => {
|
|
|
+ realplay(state.wsUrl);
|
|
|
+ }, 100);
|
|
|
+ },
|
|
|
+ windowEventOver: function (iWndIndex) {
|
|
|
+ //鼠标移过回调
|
|
|
+ // console.log('鼠标移过回调', iWndIndex);
|
|
|
+ },
|
|
|
+ windowEventOut: function (iWndIndex) {
|
|
|
+ //鼠标移出回调
|
|
|
+ //console.log(iWndIndex);
|
|
|
+ },
|
|
|
+ windowEventUp: function (iWndIndex) {
|
|
|
+ //鼠标mouseup事件回调
|
|
|
+ //console.log(iWndIndex);
|
|
|
+ // console.log('鼠标mouseup事件回调')
|
|
|
+ // fullScreen(false)
|
|
|
+ },
|
|
|
+ windowFullCcreenChange: function (bFull) {
|
|
|
+ //全屏切换回调
|
|
|
+ console.log('全屏切换回调fullScreen callback: ', bFull);
|
|
|
+ if (!bFull) {
|
|
|
+ console.log('退出全屏');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ firstFrameDisplay: function (iWndIndex, iWidth, iHeight) {
|
|
|
+ //首帧显示回调
|
|
|
+ console.log('firstFrame loaded callback: ', iWndIndex, iWidth, iHeight);
|
|
|
+ },
|
|
|
+ performanceLack: function () {
|
|
|
+ //性能不足回调
|
|
|
+ console.log('performanceLack callback: ');
|
|
|
+ stopPlay();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ state.player.JS_Resize(state.idWidth, state.idHeight).then(
|
|
|
+ () => {
|
|
|
+ console.info('JS_Resize success');
|
|
|
+ },
|
|
|
+ (err) => {
|
|
|
+ console.info('JS_Resize failed');
|
|
|
+ }
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
+// 开始播放
|
|
|
+const realplay = async (url) => {
|
|
|
+ console.log('realplay', url, state.mode);
|
|
|
+ state.player &&
|
|
|
+ state.player.JS_Play(url, { playURL: url, mode: state.mode }, 0).then(
|
|
|
+ () => {
|
|
|
+ console.log('realplay success 播放成功');
|
|
|
+ state.player && state.player.JS_Resize();
|
|
|
+ state.isLoading = false;
|
|
|
+ emits('onPlaying');
|
|
|
+ },
|
|
|
+ (e) => {
|
|
|
+ emits('onPlayError');
|
|
|
+ console.error('playerror', e);
|
|
|
+ }
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
+// 停止播放
|
|
|
+const stopPlay = () => {
|
|
|
+ state.player &&
|
|
|
+ state.player.JS_StopRealPlayAll().then(
|
|
|
+ () => {
|
|
|
+ console.log('JS_StopRealPlayAll success 停止播放');
|
|
|
+ },
|
|
|
+ (err) => {
|
|
|
+ console.log('JS_StopRealPlayAll fail', err);
|
|
|
+ }
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
+// 整体全屏
|
|
|
+const fullScreen = (type) => {
|
|
|
+ state.player &&
|
|
|
+ state.player.JS_FullScreenDisplay(type).then(
|
|
|
+ () => {
|
|
|
+ console.log('JS_FullScreenDisplay success ');
|
|
|
+ },
|
|
|
+ (err) => {
|
|
|
+ console.log('JS_FullScreenDisplay fail', err);
|
|
|
+ }
|
|
|
+ );
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss">
|
|
|
+.player-box {
|
|
|
+ position: relative;
|
|
|
+ display: inline-flex;
|
|
|
+ justify-content: center;
|
|
|
+ align-items: center;
|
|
|
+
|
|
|
+ .playWnd {
|
|
|
+ z-index: 10;
|
|
|
+ }
|
|
|
+
|
|
|
+ .loader {
|
|
|
+ position: absolute;
|
|
|
+ z-index: 10;
|
|
|
+ left: calc(1000% - 32px) / 2;
|
|
|
+ top: calc(1000% - 32px) / 2;
|
|
|
+ width: 32px;
|
|
|
+ height: 32px;
|
|
|
+ background: url('@/assets/img/ajax-loader.gif');
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|