index.vue
2.6 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<template>
<view class="content">
<video id='video' class="video" :poster="poster" :src="url" direction="-90" show-mute-btn
@timeupdate="timeupdate" @play="onstart" @pause="onpause" @ended="onfinish" @error="onfail"></video>
<image v-if="showPic" :src="poster" style="width: 750rpx;height: 400rpx;position: absolute;left: 0;top: 0;"
mode="aspectFill"></image>
<!-- @play="onstart" -->
<!-- @pause="onpause" @ended="onfinish" @error="onfail" @waiting="waiting" @timeupdate="timeupdate" -->
<!-- @fullscreenchange="fullscreenchange" -->
</view>
</template>
<script>
import throttle from '@/utils/throttle.js'
export default {
data() {
return {
url: '',
poster: '',
lessons_id: '',
token: '',
context: null,
api: '',
showPic: true
}
},
onReady() {
this.context = uni.createVideoContext("video", this);
},
onLoad(e) {
console.log(123, e)
this.poster = e.poster
this.url = e.url
this.token = e.token
this.lessons_id = e.lessons_id
this.api = e.api
if (e.seek) {
this.$nextTick(() => {
this.seek(e.seek);
this.play();
})
}
},
methods: {
onstart(e) {
this.showPic = false
// console.log("onstart:" + JSON.stringify(e));
},
onpause(e) {
// console.log("onpause:" + JSON.stringify(e));
},
onfinish(e) {
// console.log("onfinish:" + JSON.stringify(e));
},
onfail(e) {
// console.log("onfail:" + JSON.stringify(e));
},
fullscreenchange(e) {
// console.log("fullscreenchange:" + JSON.stringify(e));
},
waiting(e) {
// console.log("waiting:" + JSON.stringify(e));
},
timeupdate(e) {
this.showPic = false
throttle(() => {
uni.request({
url: this.api + 'api/course.learning/syncUserLearningRecord',
header: {
token: this.token,
},
data: {
lessons_id: this.lessons_id
},
complete(res) {
console.log("timeupdate:" + JSON.stringify(res));
}
})
}, 60000, false)
},
play() {
this.context.play();
},
// pause() {
// this.context.pause();
// },
seek(time) {
this.context.seek(time);
},
// stop() {
// this.context.stop();
// },
// fullScreen() {
// this.context.requestFullScreen({
// direction: 90
// });
// },
// exitFullScreen() {
// this.context.exitFullScreen();
// },
}
}
</script>
<style lang="scss" scoped>
.content {
width: 750rpx;
height: 400rpx;
overflow: hidden;
position: relative;
}
.video {
width: 750rpx;
height: 400rpx;
}
</style>