|
7 | 7 | <div class="playing-mask" ref="touchMask" v-if="showToolbox && !isDisabled" @click="play"></div>
|
8 | 8 | <div class="nut-video-play-btn" v-if="showToolbox && !isDisabled" ref="palyBtn" v-show="!state.playing"
|
9 | 9 | @click="play"></div>
|
10 |
| - <div class="nut-video-controller" v-show="showToolbox && !isDisabled"> |
| 10 | + <div class="nut-video-controller" v-show="showToolbox && !isDisabled" |
| 11 | + :class="{'show-control': !state.playing,'hide-control':state.playing}"> |
11 | 12 | <div class="control-play-btn" @click="play"></div>
|
12 | 13 | <div class="current-time">{{ videoSet.displayTime }}</div>
|
13 | 14 | <div class="progress-container">
|
|
22 | 23 | </div>
|
23 | 24 | </div>
|
24 | 25 | <div class="duration-time">{{ videoSet.totalTime }}</div>
|
25 |
| - <div class="volume" @click="handleMuted"></div> |
| 26 | + <div class="volume" @click="handleMuted" :class="{'muted':state.isMuted}"></div> |
26 | 27 | <div class="fullscreen-icon" @click="fullScreen"></div>
|
27 | 28 | </div>
|
28 | 29 | <!-- 错误弹窗 -->
|
|
37 | 38 | export default {
|
38 | 39 | name: 'nut-video',
|
39 | 40 | props: {
|
40 |
| - src: '', |
41 |
| - playsinline: { |
42 |
| - type: Boolean, |
43 |
| - default: false |
| 41 | + sources: { |
| 42 | + type: Array, |
| 43 | + default() { |
| 44 | + return [] |
| 45 | + } |
44 | 46 | },
|
45 |
| - sources: Array, |
46 | 47 | options: {
|
47 | 48 | type: Object,
|
48 | 49 | default() {
|
|
60 | 61 | },
|
61 | 62 | required: true
|
62 | 63 | },
|
| 64 | + model: { |
| 65 | + type: String, |
| 66 | + default: '' |
| 67 | + } |
63 | 68 | },
|
64 | 69 | data() {
|
65 | 70 | return {
|
|
87 | 92 | }
|
88 | 93 | },
|
89 | 94 | state: {
|
90 |
| - contrlShow: false, |
| 95 | + controlShow: true, |
91 | 96 | vol: 0.5, //音量
|
92 | 97 | currentTime: 0, //当前时间
|
93 | 98 | fullScreen: false,
|
94 | 99 | playing: false, //是否正在播放
|
95 | 100 | isLoading: false,
|
96 | 101 | isEnd: false,
|
97 |
| - isError: false |
| 102 | + isError: false, |
| 103 | + isMuted: false |
98 | 104 | },
|
99 |
| - showTouchMask: false |
| 105 | + showTouchMask: false, |
100 | 106 | };
|
101 | 107 | },
|
102 | 108 | computed: {
|
103 | 109 | isDisabled() {
|
104 | 110 | return this.options.disabled
|
105 |
| - }, |
| 111 | + } |
106 | 112 |
|
107 | 113 | },
|
108 | 114 | watch: {
|
|
118 | 124 | },
|
119 | 125 | options: {
|
120 | 126 | handler(val) {
|
121 |
| -
|
| 127 | + this.state.isMuted = val.muted ? val.muted : false |
122 | 128 | },
|
123 | 129 | immediate: true
|
124 |
| - } |
| 130 | + }, |
| 131 | + // model: { |
| 132 | + // handler(val) { |
| 133 | + // if (val) { |
| 134 | + // if (val == 'custom') { |
| 135 | + // this.state.controlShow = false; |
| 136 | + // this.showToolbox = this.options.controls ? true : false |
| 137 | + // } |
| 138 | + // } else { |
| 139 | + // this.showToolbox = false; |
| 140 | + // this.state.controlShow = this.options.controls ? true : false |
| 141 | + // } |
| 142 | + // }, |
| 143 | + // immediate: true |
| 144 | +
|
| 145 | + // } |
125 | 146 | },
|
126 | 147 | mounted() {
|
127 | 148 | this.init();
|
|
172 | 193 | this.player.pos = $player.getBoundingClientRect();
|
173 | 194 | this.progressBar.pos = $progress.getBoundingClientRect();
|
174 | 195 | this.videoSet.progress.width = Math.round($progress.getBoundingClientRect().width);
|
175 |
| - console.log(this.progressBar.pos) |
176 | 196 | },
|
177 | 197 | play() {
|
178 |
| - this.state.playing = !this.state.playing; |
| 198 | +
|
179 | 199 |
|
180 | 200 | if (this.options.autoplay && this.options.disabled) {
|
181 | 201 | this.state.playing = true;
|
| 202 | + // this.state.controlShow = false |
182 | 203 | return false;
|
183 | 204 | }
|
| 205 | + this.state.playing = !this.state.playing; |
184 | 206 | if (this.videoElm) {
|
185 | 207 |
|
186 |
| - // if (this.state.playing) { |
187 |
| - // this.videoElm.play(); |
188 |
| - // this.videoElm.addEventListener('ended', this.playEnded); |
189 |
| - // this.$emit('play', this.video); |
190 |
| - // } else { |
191 |
| - // this.videoElm.pause(); |
192 |
| - // this.$emit('pause', this.video); |
193 |
| - // } |
194 | 208 | // 播放状态
|
195 | 209 | if (this.state.playing) {
|
196 | 210 | try {
|
197 |
| - // console.log(111) |
198 | 211 | this.videoElm.play();
|
199 |
| - // this.isPauseTouch = false; |
200 | 212 | // 监听缓存进度
|
201 | 213 | this.videoElm.addEventListener('progress', e => {
|
202 | 214 | this.getLoadTime();
|
|
213 | 225 | }
|
214 | 226 | // 停止状态
|
215 | 227 | else {
|
216 |
| - // console.log('pu') |
217 |
| - this.isPauseTouch = true; |
218 | 228 | this.videoElm.pause();
|
219 | 229 | this.$emit('pause', this.videoElm);
|
| 230 | +
|
220 | 231 | }
|
221 | 232 | }
|
222 | 233 | },
|
223 | 234 | // 音量控制
|
224 | 235 | volumeHandle() {
|
225 |
| - this.state.vol = this.videoElm.volume; |
| 236 | + this.state.vol = this.options.volume; |
226 | 237 | },
|
227 | 238 | // 静音控制
|
228 | 239 | handleMuted() {
|
229 |
| -
|
| 240 | + this.state.isMuted = !this.state.isMuted |
| 241 | + this.videoElm.muted = this.state.isMuted |
230 | 242 | },
|
231 | 243 | playEnded() {
|
232 |
| - // console.log('ended') |
233 | 244 | this.state.playing = false;
|
234 | 245 | this.state.isEnd = true;
|
235 | 246 | this.state.controlBtnShow = true;
|
|
247 | 258 | fullScreen() {
|
248 | 259 | if (!this.state.fullScreen) {
|
249 | 260 | this.state.fullScreen = true;
|
250 |
| - this.video.webkitRequestFullScreen(); |
| 261 | + this.videoElm.webkitRequestFullScreen(); |
251 | 262 | } else {
|
252 | 263 | this.state.fullScreen = false;
|
253 | 264 | document.webkitCancelFullScreen();
|
|
262 | 273 | // 赋值时长
|
263 | 274 | this.videoSet.totalTime = this.timeFormat(this.videoElm.duration);
|
264 | 275 | this.videoSet.displayTime = this.timeFormat(this.videoElm.currentTime);
|
265 |
| - // console.log(this.videoSet, this.timeFormat(this.videoElm.duration), this.timeFormat(this.videoElm.currentTime), this.videoSet.progress.current) |
266 | 276 | },
|
267 | 277 | timeFormat(t) {
|
268 | 278 | var h = Math.floor(t / 3600);
|
|
287 | 297 | },
|
288 | 298 | // 获取缓存时间
|
289 | 299 | getLoadTime() {
|
290 |
| - // console.log('缓存了...',this.videoElm.buffered.end(0)); |
291 |
| - this.videoSet.loaded = (this.videoElm.buffered.end(0) / this.videoElm.duration) * 100; |
| 300 | + if (this.videoSet.loaded) |
| 301 | + this.videoSet.loaded = (this.videoElm.buffered.end(0) / this.videoElm.duration) * 100; |
292 | 302 | },
|
293 | 303 | getTime() {
|
294 | 304 | this.videoElm.addEventListener('durationchange', e => {
|
|
302 | 312 | // 拖动播放进度
|
303 | 313 | touchSlidSrart(e) { },
|
304 | 314 | touchSlidMove(e) {
|
305 |
| - console.log("触摸中..."); |
306 | 315 | let currentX = e.targetTouches[0].pageX;
|
307 | 316 | let offsetX = currentX - this.progressBar.pos.left;
|
308 | 317 | // 边界检测
|
|
320 | 329 |
|
321 | 330 | },
|
322 | 331 | touchSlidEnd(e) {
|
323 |
| - console.log("触摸结束..."); |
324 | 332 | let currentX = e.changedTouches[0].pageX;
|
325 | 333 | let offsetX = currentX - this.progressBar.pos.left;
|
326 | 334 | this.videoSet.progress.current = offsetX;
|
|
0 commit comments