|
@@ -5,11 +5,13 @@
|
|
|
<script>
|
|
<script>
|
|
|
import { videoUrl } from '@/api/media/video'
|
|
import { videoUrl } from '@/api/media/video'
|
|
|
import DPlayer from 'dplayer'
|
|
import DPlayer from 'dplayer'
|
|
|
|
|
+const flv = require('flv.js')
|
|
|
const hls = require('hls.js')
|
|
const hls = require('hls.js')
|
|
|
export default {
|
|
export default {
|
|
|
name: 'Play',
|
|
name: 'Play',
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
|
|
+ flv,
|
|
|
hls,
|
|
hls,
|
|
|
videoId: ''
|
|
videoId: ''
|
|
|
}
|
|
}
|
|
@@ -56,6 +58,7 @@ export default {
|
|
|
videoUrl(videoId)
|
|
videoUrl(videoId)
|
|
|
.then(res => {
|
|
.then(res => {
|
|
|
if (res.code === 0) {
|
|
if (res.code === 0) {
|
|
|
|
|
+ // TODO 返回一个 dplayer 播放器对象,包含一些常用的属性
|
|
|
var coverUrl = res.data.coverUrl
|
|
var coverUrl = res.data.coverUrl
|
|
|
var videoUrl = res.data.videoUrl
|
|
var videoUrl = res.data.videoUrl
|
|
|
this.initDplayer(this.videoId, coverUrl, videoUrl)
|
|
this.initDplayer(this.videoId, coverUrl, videoUrl)
|
|
@@ -73,9 +76,11 @@ export default {
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
initDplayer(videoId, coverUrl, videoUrl) {
|
|
initDplayer(videoId, coverUrl, videoUrl) {
|
|
|
- new DPlayer({
|
|
|
|
|
|
|
+ const vidId = videoId
|
|
|
|
|
+ const dp = new DPlayer({
|
|
|
container: document.querySelector('#dplayer'),
|
|
container: document.querySelector('#dplayer'),
|
|
|
lang: 'zh-cn',
|
|
lang: 'zh-cn',
|
|
|
|
|
+ autoplay: false,
|
|
|
screenshot: true,
|
|
screenshot: true,
|
|
|
video: {
|
|
video: {
|
|
|
pic: coverUrl,
|
|
pic: coverUrl,
|
|
@@ -93,6 +98,41 @@ export default {
|
|
|
unlimited: true
|
|
unlimited: true
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+ // 跳转到指定秒
|
|
|
|
|
+ // dp.seek(100)
|
|
|
|
|
+
|
|
|
|
|
+ dp.on('play', function() {
|
|
|
|
|
+ console.log(vidId + ' 播放开始' + dp.video.currentTime)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ dp.on('pause', function() {
|
|
|
|
|
+ console.log(vidId + ' 播放暂停' + dp.video.currentTime)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ dp.on('ended', function() {
|
|
|
|
|
+ // TODO 当前视频播放完成后判断是否继续播放相关推荐中的视频
|
|
|
|
|
+ console.log(vidId + ' 播放结束' + dp.video.currentTime)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ dp.on('seeking', function() {
|
|
|
|
|
+ console.log(vidId + ' seeking 事件 ' + dp.video.currentTime)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ dp.on('seeked', function() {
|
|
|
|
|
+ console.log(vidId + ' seeked 事件' + dp.video.currentTime)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ const interval = 5
|
|
|
|
|
+ var i = 0
|
|
|
|
|
+ dp.on('progress', function() {
|
|
|
|
|
+ console.log('i = ' + i)
|
|
|
|
|
+ if (i % interval === 0) {
|
|
|
|
|
+ // TODO 每 5s 向后端报告一次播放进度
|
|
|
|
|
+ console.log(vidId + ' 播放进度 ' + dp.video.currentTime)
|
|
|
|
|
+ }
|
|
|
|
|
+ i++
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|