|
@@ -9,7 +9,6 @@
|
|
ref="VideoMedia"
|
|
ref="VideoMedia"
|
|
:id="videoId"
|
|
:id="videoId"
|
|
muted
|
|
muted
|
|
- @ended="destroyPlayer"
|
|
|
|
@pause="playerPaused"
|
|
@pause="playerPaused"
|
|
@play="playerPlaying"
|
|
@play="playerPlaying"
|
|
></video>
|
|
></video>
|
|
@@ -31,7 +30,7 @@
|
|
>
|
|
>
|
|
<i :class="['icon', !muted ? 'icon-audio-act' : 'icon-audio']"></i>
|
|
<i :class="['icon', !muted ? 'icon-audio-act' : 'icon-audio']"></i>
|
|
</div>
|
|
</div>
|
|
- <div
|
|
|
|
|
|
+ <!-- <div
|
|
v-if="liveUrl && !result.error && !loading && flvPlayer"
|
|
v-if="liveUrl && !result.error && !loading && flvPlayer"
|
|
class="media-video-play"
|
|
class="media-video-play"
|
|
@click.stop="playOrPausePlayer"
|
|
@click.stop="playOrPausePlayer"
|
|
@@ -39,13 +38,13 @@
|
|
<i
|
|
<i
|
|
:class="[this.paused ? 'el-icon-video-play' : 'el-icon-video-pause']"
|
|
:class="[this.paused ? 'el-icon-video-play' : 'el-icon-video-pause']"
|
|
></i>
|
|
></i>
|
|
- </div>
|
|
|
|
|
|
+ </div> -->
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script>
|
|
<script>
|
|
-import flvjs from "flv.js";
|
|
|
|
-// doc: https://github.com/bilibili/flv.js/blob/42343088f22619cf014a057b3878fe3d320016a6/docs/api.md
|
|
|
|
|
|
+import TCPlayer from "tcplayer.js";
|
|
|
|
+// doc: https://cloud.tencent.com/document/product/881/30820
|
|
import timeMixin from "../../../mixins/timeMixin";
|
|
import timeMixin from "../../../mixins/timeMixin";
|
|
|
|
|
|
export default {
|
|
export default {
|
|
@@ -67,7 +66,6 @@ export default {
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
videoId: `video${this._uid}`,
|
|
videoId: `video${this._uid}`,
|
|
- videoElement: null,
|
|
|
|
flvPlayer: null,
|
|
flvPlayer: null,
|
|
muted: true,
|
|
muted: true,
|
|
paused: false,
|
|
paused: false,
|
|
@@ -95,48 +93,51 @@ export default {
|
|
methods: {
|
|
methods: {
|
|
initVideo() {
|
|
initVideo() {
|
|
if (!this.liveUrl) return;
|
|
if (!this.liveUrl) return;
|
|
- if (!flvjs.isSupported()) {
|
|
|
|
- this.result = {
|
|
|
|
- error: true,
|
|
|
|
- message: "不支持播放",
|
|
|
|
- };
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
this.loading = true;
|
|
this.loading = true;
|
|
|
|
|
|
- this.flvPlayer = flvjs.createPlayer(
|
|
|
|
- {
|
|
|
|
- type: "flv",
|
|
|
|
- isLive: true,
|
|
|
|
- hasAudio: true,
|
|
|
|
- url: this.liveUrl,
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- fixAudioTimestampGap: false,
|
|
|
|
- enableStashBuffer: true,
|
|
|
|
- stashInitialSize: false,
|
|
|
|
- }
|
|
|
|
- );
|
|
|
|
- this.flvPlayer.attachMediaElement(this.$refs.VideoMedia);
|
|
|
|
- this.flvPlayer.load();
|
|
|
|
- this.flvPlayer.play();
|
|
|
|
- this.flvPlayer.on(flvjs.Events.ERROR, this.playError);
|
|
|
|
- this.flvPlayer.on(flvjs.Events.METADATA_ARRIVED, () => {
|
|
|
|
|
|
+ this.flvPlayer = TCPlayer(this.videoId, {
|
|
|
|
+ controls: false,
|
|
|
|
+ autoplay: true,
|
|
|
|
+ muted: false,
|
|
|
|
+ bigPlayButton: false,
|
|
|
|
+ });
|
|
|
|
+ this.flvPlayer.src(this.liveUrl);
|
|
|
|
+ this.flvPlayer.ready(() => {
|
|
this.loading = false;
|
|
this.loading = false;
|
|
- console.log("视频信息获取成功");
|
|
|
|
- this.retryCount = 0;
|
|
|
|
|
|
+ this.flvPlayer.volume(0);
|
|
});
|
|
});
|
|
- this.flvPlayer.on(
|
|
|
|
- flvjs.Events.STATISTICS_INFO,
|
|
|
|
- this.statisticsInfoEventHandle
|
|
|
|
- );
|
|
|
|
|
|
+ this.flvPlayer.on("error", this.playError);
|
|
|
|
+ this.flvPlayer.on("ended", this.destroyPlayer);
|
|
|
|
+ },
|
|
|
|
+ playError(code) {
|
|
|
|
+ switch (code) {
|
|
|
|
+ case 1:
|
|
|
|
+ console.log("媒体问题,准备重试!");
|
|
|
|
+ this.retryPlay();
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ console.log("网络问题,准备重试!");
|
|
|
|
+ this.retryPlay();
|
|
|
|
+ break;
|
|
|
|
+ case 3:
|
|
|
|
+ console.log("解码问题,准备重试!");
|
|
|
|
+ this.retryPlay();
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ console.log(code + "未知问题,无法播放!");
|
|
|
|
+ this.retryPlay();
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
},
|
|
},
|
|
statisticsInfoEventHandle(res) {
|
|
statisticsInfoEventHandle(res) {
|
|
if (this.lastDecodedFrames === 0) {
|
|
if (this.lastDecodedFrames === 0) {
|
|
this.lastDecodedFrames = res.decodedFrames;
|
|
this.lastDecodedFrames = res.decodedFrames;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- if (this.lastDecodedFrames === res.decodedFrames && !this.paused) {
|
|
|
|
|
|
+ if (
|
|
|
|
+ this.lastDecodedFrames === res.decodedFrames &&
|
|
|
|
+ !this.flvPlayer.paused
|
|
|
|
+ ) {
|
|
this.lastDecodedFrames = 0;
|
|
this.lastDecodedFrames = 0;
|
|
console.log("卡住了,准备重试!");
|
|
console.log("卡住了,准备重试!");
|
|
this.retryPlay();
|
|
this.retryPlay();
|
|
@@ -144,25 +145,6 @@ export default {
|
|
this.lastDecodedFrames = res.decodedFrames;
|
|
this.lastDecodedFrames = res.decodedFrames;
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- playError(errorType) {
|
|
|
|
- switch (errorType) {
|
|
|
|
- case flvjs.ErrorTypes.NETWORK_ERROR:
|
|
|
|
- console.log("网络问题,准备重试!");
|
|
|
|
- this.retryPlay();
|
|
|
|
- break;
|
|
|
|
- case flvjs.ErrorTypes.MEDIA_ERROR:
|
|
|
|
- console.log("媒体问题,准备重试!");
|
|
|
|
- this.retryPlay();
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- console.log("未知问题,无法播放!");
|
|
|
|
- this.result = {
|
|
|
|
- error: true,
|
|
|
|
- message: "播放失败",
|
|
|
|
- };
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
retryPlay() {
|
|
retryPlay() {
|
|
if (this.retryCount >= this.maxRetryCount) {
|
|
if (this.retryCount >= this.maxRetryCount) {
|
|
console.log("已尝试最大次数重新播放!");
|
|
console.log("已尝试最大次数重新播放!");
|
|
@@ -180,30 +162,27 @@ export default {
|
|
console.log("已重新播放");
|
|
console.log("已重新播放");
|
|
}, 1000);
|
|
}, 1000);
|
|
},
|
|
},
|
|
- playOrPausePlayer() {
|
|
|
|
- if (!this.flvPlayer) return;
|
|
|
|
- this.paused ? this.flvPlayer.play() : this.flvPlayer.pause();
|
|
|
|
- },
|
|
|
|
destroyPlayer() {
|
|
destroyPlayer() {
|
|
if (!this.flvPlayer) return;
|
|
if (!this.flvPlayer) return;
|
|
this.flvPlayer.pause();
|
|
this.flvPlayer.pause();
|
|
- this.flvPlayer.unload();
|
|
|
|
- this.flvPlayer.detachMediaElement();
|
|
|
|
- this.flvPlayer.destroy();
|
|
|
|
|
|
+ this.flvPlayer.dispose();
|
|
this.flvPlayer = null;
|
|
this.flvPlayer = null;
|
|
this.clearSetTs();
|
|
this.clearSetTs();
|
|
},
|
|
},
|
|
mutedPlayer(muted) {
|
|
mutedPlayer(muted) {
|
|
if (!this.flvPlayer) return;
|
|
if (!this.flvPlayer) return;
|
|
- this.flvPlayer.muted = muted;
|
|
|
|
- this.muted = this.flvPlayer.muted;
|
|
|
|
|
|
+ const volume = muted ? 0 : 1;
|
|
|
|
+ this.flvPlayer.volume(volume);
|
|
|
|
+ this.muted = muted;
|
|
},
|
|
},
|
|
videoMuted() {
|
|
videoMuted() {
|
|
if (!this.flvPlayer) return;
|
|
if (!this.flvPlayer) return;
|
|
- const muted = this.flvPlayer.muted;
|
|
|
|
|
|
+ const volume = this.flvPlayer.volume();
|
|
|
|
+ console.log(volume);
|
|
this.$emit("muted-change");
|
|
this.$emit("muted-change");
|
|
- this.flvPlayer.muted = !muted;
|
|
|
|
- this.muted = this.flvPlayer.muted;
|
|
|
|
|
|
+ const nvolume = volume === 1 ? 0 : 1;
|
|
|
|
+ this.flvPlayer.volume(nvolume);
|
|
|
|
+ this.muted = nvolume === 0;
|
|
},
|
|
},
|
|
reloadVideo() {
|
|
reloadVideo() {
|
|
this.result = {
|
|
this.result = {
|
|
@@ -217,6 +196,10 @@ export default {
|
|
this.retryCount++;
|
|
this.retryCount++;
|
|
});
|
|
});
|
|
},
|
|
},
|
|
|
|
+ playOrPausePlayer() {
|
|
|
|
+ if (!this.flvPlayer) return;
|
|
|
|
+ this.paused ? this.flvPlayer.play() : this.flvPlayer.pause();
|
|
|
|
+ },
|
|
playerPaused() {
|
|
playerPaused() {
|
|
this.paused = true;
|
|
this.paused = true;
|
|
console.log(this.paused);
|
|
console.log(this.paused);
|