1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| <script> export default { name: "cameraVideo", props: ["videoData",'autoPlay'], watch: {}, methods: { loadVideo() { console.log("data alive", this.videoData); this.player && this.destroy(); this.player = flvjs.createPlayer({ type: "flv", isLive: true, url: this.videoData, hasAudio: false, hasVideo: true, cors: true, }); this.player.attachMediaElement(this.$refs.myCameraVideoPlayer); this.player.load(); this.bindEvents(); this.startVideo(); }, bindEvents() { console.log(flvjs); this.player.on(flvjs.Events.ERROR, this.handleErr); this.player.on(flvjs.Events.LOADING_COMPLETE, this.handleErr); }, handleErr() { if (this.player) { this.player.pause(); this.player.unload(); this.player.detachMediaElement(); this.player.destroy(); this.player = null; this.loadVideo(); } }, startVideo() { if (this.player) { this.player.play(); } }, pause() { this.player && this.player.pause(); }, destroy() { if (this.player) { this.player.pause(); this.player.unload(); this.player.detachMediaElement(); this.player.destroy(); this.player = null; } }, }, data() { return { supported: false, player: null, }; }, mounted() { this.player = null; this.supported = flvjs.isSupported(); if(this.autoPlay){ this.loadVideo(); } }, beforeDestroy() { console.log("beforeDestroy"); this.destroy(); }, }; </script>
|