|
@@ -5,15 +5,18 @@
|
|
|
<script>
|
|
<script>
|
|
|
import { videoUrl } from '@/api/media/video'
|
|
import { videoUrl } from '@/api/media/video'
|
|
|
import DPlayer from 'dplayer'
|
|
import DPlayer from 'dplayer'
|
|
|
-// const dashjs = require('dashjs')
|
|
|
|
|
-const flv = require('flv.js')
|
|
|
|
|
const hls = require('hls.js')
|
|
const hls = require('hls.js')
|
|
|
|
|
+const dashjs = require('dashjs')
|
|
|
|
|
+const ShakaPlayer = require('shaka-player')
|
|
|
|
|
+const flv = require('flv.js')
|
|
|
export default {
|
|
export default {
|
|
|
name: 'Play',
|
|
name: 'Play',
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
flv,
|
|
flv,
|
|
|
|
|
+ dashjs,
|
|
|
hls,
|
|
hls,
|
|
|
|
|
+ ShakaPlayer,
|
|
|
videoId: ''
|
|
videoId: ''
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
@@ -62,7 +65,16 @@ export default {
|
|
|
// TODO 返回一个 dplayer 播放器对象,包含一些常用的属性
|
|
// 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)
|
|
|
|
|
|
|
+ var urlType = res.data.urlType
|
|
|
|
|
+ if (urlType === 'mp4') {
|
|
|
|
|
+ this.initMp4Player(this.videoId, coverUrl, videoUrl)
|
|
|
|
|
+ } else if (urlType === 'hls') {
|
|
|
|
|
+ this.initHlsPlayer(this.videoId, coverUrl, videoUrl)
|
|
|
|
|
+ } else if (urlType === 'dash') {
|
|
|
|
|
+ this.initDashPlayer(this.videoId, coverUrl, videoUrl)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.log('无法识别 url 类型')
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
this.$notify({
|
|
this.$notify({
|
|
|
title: res.code,
|
|
title: res.code,
|
|
@@ -76,9 +88,9 @@ export default {
|
|
|
this.$message.error(error.message)
|
|
this.$message.error(error.message)
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
- initDplayer(videoId, coverUrl, videoUrl) {
|
|
|
|
|
|
|
+ initMp4Player(videoId, coverUrl, videoUrl) {
|
|
|
const vidId = videoId
|
|
const vidId = videoId
|
|
|
- const dp = new DPlayer({
|
|
|
|
|
|
|
+ const player = new DPlayer({
|
|
|
container: document.querySelector('#dplayer'),
|
|
container: document.querySelector('#dplayer'),
|
|
|
lang: 'zh-cn',
|
|
lang: 'zh-cn',
|
|
|
autoplay: false,
|
|
autoplay: false,
|
|
@@ -104,37 +116,76 @@ export default {
|
|
|
// 跳转到指定秒
|
|
// 跳转到指定秒
|
|
|
// dp.seek(100)
|
|
// dp.seek(100)
|
|
|
|
|
|
|
|
- dp.on('play', function() {
|
|
|
|
|
- console.log(vidId + ' 播放开始' + dp.video.currentTime)
|
|
|
|
|
|
|
+ player.on('play', function() {
|
|
|
|
|
+ console.log(vidId + ' 播放开始' + player.video.currentTime)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- dp.on('pause', function() {
|
|
|
|
|
- console.log(vidId + ' 播放暂停' + dp.video.currentTime)
|
|
|
|
|
|
|
+ player.on('pause', function() {
|
|
|
|
|
+ console.log(vidId + ' 播放暂停' + player.video.currentTime)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- dp.on('ended', function() {
|
|
|
|
|
|
|
+ player.on('ended', function() {
|
|
|
// TODO 当前视频播放完成后判断是否继续播放相关推荐中的视频
|
|
// TODO 当前视频播放完成后判断是否继续播放相关推荐中的视频
|
|
|
- console.log(vidId + ' 播放结束' + dp.video.currentTime)
|
|
|
|
|
|
|
+ console.log(vidId + ' 播放结束' + player.video.currentTime)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- dp.on('seeking', function() {
|
|
|
|
|
- console.log(vidId + ' seeking 事件 ' + dp.video.currentTime)
|
|
|
|
|
|
|
+ player.on('seeking', function() {
|
|
|
|
|
+ console.log(vidId + ' seeking 事件 ' + player.video.currentTime)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- dp.on('seeked', function() {
|
|
|
|
|
- console.log(vidId + ' seeked 事件' + dp.video.currentTime)
|
|
|
|
|
|
|
+ player.on('seeked', function() {
|
|
|
|
|
+ console.log(vidId + ' seeked 事件' + player.video.currentTime)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
const interval = 5
|
|
const interval = 5
|
|
|
var i = 0
|
|
var i = 0
|
|
|
- dp.on('progress', function() {
|
|
|
|
|
|
|
+ player.on('progress', function() {
|
|
|
console.log('i = ' + i)
|
|
console.log('i = ' + i)
|
|
|
if (i % interval === 0) {
|
|
if (i % interval === 0) {
|
|
|
// TODO 每 5s 向后端报告一次播放进度
|
|
// TODO 每 5s 向后端报告一次播放进度
|
|
|
- console.log(vidId + ' 播放进度 ' + dp.video.currentTime)
|
|
|
|
|
|
|
+ console.log(vidId + ' 播放进度 ' + player.video.currentTime)
|
|
|
}
|
|
}
|
|
|
i++
|
|
i++
|
|
|
})
|
|
})
|
|
|
|
|
+ },
|
|
|
|
|
+ initHlsPlayer(videoId, coverUrl, videoUrl) {
|
|
|
|
|
+ new DPlayer({
|
|
|
|
|
+ container: document.querySelector('#dplayer'),
|
|
|
|
|
+ lang: 'zh-cn',
|
|
|
|
|
+ autoplay: false,
|
|
|
|
|
+ screenshot: true,
|
|
|
|
|
+ video: {
|
|
|
|
|
+ pic: coverUrl,
|
|
|
|
|
+ url: videoUrl,
|
|
|
|
|
+ type: 'hls'
|
|
|
|
|
+ },
|
|
|
|
|
+ logo: '/logo.png'
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ initDashPlayer(videoId, coverUrl, videoUrl) {
|
|
|
|
|
+ console.log('初始化 dash 播放器')
|
|
|
|
|
+ new DPlayer({
|
|
|
|
|
+ container: document.querySelector('#dplayer'),
|
|
|
|
|
+ lang: 'zh-cn',
|
|
|
|
|
+ autoplay: false,
|
|
|
|
|
+ screenshot: true,
|
|
|
|
|
+ video: {
|
|
|
|
|
+ pic: coverUrl,
|
|
|
|
|
+ url: videoUrl,
|
|
|
|
|
+ type: 'shakaDash',
|
|
|
|
|
+ customType: {
|
|
|
|
|
+ shakaDash: function(video, player) {
|
|
|
|
|
+ console.log(video)
|
|
|
|
|
+ console.log(player)
|
|
|
|
|
+ console.log('-------------------')
|
|
|
|
|
+ var src = video.src
|
|
|
|
|
+ var playerShaka = new ShakaPlayer(video) // 将会修改 video.src
|
|
|
|
|
+ playerShaka.load(src)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ logo: '/logo.png'
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|