1
Surpriseplus
2022-09-16 a7e5110ef3f5fe3c9205f7d1a526b9fbbb55d826
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<template>
    <div class="box">
        <div id="Player" style="height: 540px;"></div>
    </div>
</template>
<script>
    export default {
        props: ["url"],
        data() {
            return {
                voidHeight: "",
                player: null,
                // src:"https://c32g3201.ply.univms.univdn.net:10443/10000051/uni0321122030208211775/uni0320031122061404794581.flv?group_id=uni0321122030208211775&v_codec=h264&key=e07c6dd502ee0d112517d419e6ec3dbf&time=1654705820"
            }
        },
        mounted() {
            // 页面加载完成后,初始化
            this.$nextTick(() => {
                console.log(this.url);
                if (this.player != null && this.url != "") {
                    this.playPlause();
                    this.playerClose();
                    this.player = null;
                }
                // 实例化播放器
                this.player = new WasmPlayer(null, 'Player', this.callbackfun, {
                    Height: true
                })
                // 调用播放
                this.player.play(this.url, 1)
            });
        },
        methods: {
            callbackfun(e) {
                if(e.code==502){
                    this.player.destroy(this.url);
                }
                console.log('callbackfun', e);
                
            },
 
            //组件暂停
            playPlause() {
                this.player.pause(this.url);
            },
 
            //组件关闭
            playerClose() {
                this.player.destroy(this.url);
            },
 
 
        },
 
        beforeDestroy() {
            if (this.player != null && this.url != "") {
                //this.playPlause();
                this.playerClose();
            }
        },
 
        watch: {
            url: {
                handler(newVal, oldVal) {
                    console.log(url);
                    this.url = newVal;
                    if (this.player != null && this.url != "") {
                        //this.playPlause();
                        this.playerClose();
                        //this.player=null;
                    }
                    this.player = new WasmPlayer(null, 'Player', this.callbackfun, {
                        Height: true
                    })
                    // 调用播放
                    this.player.play(this.url, 1)
                },
            }
 
 
        },
 
 
 
 
 
 
 
 
    }
</script>
<style scoped="scoped" lang="less">
    .box {
        width: 100%;
        height: 100%;
 
        #Player {
            height: 540px;
        }
    }
</style>