|
@@ -8,6 +8,7 @@ const hls = require('hls.js')
|
|
|
const dashjs = require('dashjs')
|
|
const dashjs = require('dashjs')
|
|
|
const flv = require('flv.js')
|
|
const flv = require('flv.js')
|
|
|
const DPlayer = require('dplayer')
|
|
const DPlayer = require('dplayer')
|
|
|
|
|
+
|
|
|
export default {
|
|
export default {
|
|
|
name: 'Play',
|
|
name: 'Play',
|
|
|
data() {
|
|
data() {
|
|
@@ -17,16 +18,16 @@ export default {
|
|
|
flv,
|
|
flv,
|
|
|
DPlayer,
|
|
DPlayer,
|
|
|
userId: 0,
|
|
userId: 0,
|
|
|
- videoId: ''
|
|
|
|
|
|
|
+ videoId: '',
|
|
|
|
|
+ playRecord: null
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
mounted() {
|
|
mounted() {
|
|
|
const userInfo = this.$store.state.user.userInfo
|
|
const userInfo = this.$store.state.user.userInfo
|
|
|
if (userInfo != null) {
|
|
if (userInfo != null) {
|
|
|
- this.userId = userInfo.userId.toString()
|
|
|
|
|
- } else {
|
|
|
|
|
- this.userId = 110101
|
|
|
|
|
|
|
+ this.userId = userInfo.userId
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
this.videoId = this.$route.params.id
|
|
this.videoId = this.$route.params.id
|
|
|
videoUrl(this.$route.params.id)
|
|
videoUrl(this.$route.params.id)
|
|
|
.then(res => {
|
|
.then(res => {
|
|
@@ -36,7 +37,7 @@ export default {
|
|
|
var videoUrl = res.data.videoUrl
|
|
var videoUrl = res.data.videoUrl
|
|
|
var urlType = res.data.urlType
|
|
var urlType = res.data.urlType
|
|
|
if (urlType === 'mp4') {
|
|
if (urlType === 'mp4') {
|
|
|
- this.initMp4Player(this.videoId, coverUrl, videoUrl)
|
|
|
|
|
|
|
+ this.initMp4Player(this.userId, this.videoId, coverUrl, videoUrl)
|
|
|
} else if (urlType === 'hls') {
|
|
} else if (urlType === 'hls') {
|
|
|
this.initHlsPlayer(this.videoId, coverUrl, videoUrl)
|
|
this.initHlsPlayer(this.videoId, coverUrl, videoUrl)
|
|
|
} else if (urlType === 'dash') {
|
|
} else if (urlType === 'dash') {
|
|
@@ -54,8 +55,7 @@ export default {
|
|
|
duration: 500
|
|
duration: 500
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
- })
|
|
|
|
|
- .catch(error => {
|
|
|
|
|
|
|
+ }).catch(error => {
|
|
|
console.error(error.message)
|
|
console.error(error.message)
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
@@ -63,136 +63,126 @@ export default {
|
|
|
// TODO 获取弹幕配置,将 videoUrl 作为本函数的回调
|
|
// TODO 获取弹幕配置,将 videoUrl 作为本函数的回调
|
|
|
danmakuConfig() {
|
|
danmakuConfig() {
|
|
|
},
|
|
},
|
|
|
- initMp4Player(videoId, coverUrl, videoUrl) {
|
|
|
|
|
|
|
+ submitVideoPlayRecord(currentTime) {
|
|
|
|
|
+ if (this.playRecord == null) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.playRecord.currentTime = currentTime
|
|
|
|
|
+ submitPlayRecord(this.playRecord)
|
|
|
|
|
+ .then(res => {
|
|
|
|
|
+ if (res.code === 0) {
|
|
|
|
|
+ console.log('播放进度已发送')
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.$notify({
|
|
|
|
|
+ title: res.code,
|
|
|
|
|
+ message: res.msg,
|
|
|
|
|
+ type: 'warning',
|
|
|
|
|
+ duration: 500
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }).catch(error => {
|
|
|
|
|
+ console.error(error.message)
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ initMp4Player(userId, videoId, coverUrl, videoUrl) {
|
|
|
const player = new DPlayer({
|
|
const player = new DPlayer({
|
|
|
container: document.querySelector('#dplayer'),
|
|
container: document.querySelector('#dplayer'),
|
|
|
lang: 'zh-cn',
|
|
lang: 'zh-cn',
|
|
|
|
|
+ logo: '/logo.png',
|
|
|
autoplay: false,
|
|
autoplay: false,
|
|
|
screenshot: true,
|
|
screenshot: true,
|
|
|
video: {
|
|
video: {
|
|
|
pic: coverUrl,
|
|
pic: coverUrl,
|
|
|
url: videoUrl,
|
|
url: videoUrl,
|
|
|
type: 'auto'
|
|
type: 'auto'
|
|
|
- // type: 'dash'
|
|
|
|
|
},
|
|
},
|
|
|
- logo: '/logo.png',
|
|
|
|
|
danmaku: {
|
|
danmaku: {
|
|
|
id: videoId,
|
|
id: videoId,
|
|
|
maximum: 10000,
|
|
maximum: 10000,
|
|
|
api: '//api.reghao.cn/api/comment/danmaku/',
|
|
api: '//api.reghao.cn/api/comment/danmaku/',
|
|
|
token: 'hertube',
|
|
token: 'hertube',
|
|
|
- user: this.userId,
|
|
|
|
|
|
|
+ user: userId,
|
|
|
bottom: '15%',
|
|
bottom: '15%',
|
|
|
unlimited: true
|
|
unlimited: true
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- // 跳转到指定秒
|
|
|
|
|
- // dp.seek(100)
|
|
|
|
|
-
|
|
|
|
|
- const playRecord1 = {
|
|
|
|
|
- 'userId': 110110,
|
|
|
|
|
- 'videoId': videoId,
|
|
|
|
|
- 'currentTime': 0.0
|
|
|
|
|
|
|
+ if (userId !== 0) {
|
|
|
|
|
+ console.log('初始化 playRecord')
|
|
|
|
|
+ this.playRecord = {
|
|
|
|
|
+ 'userId': this.userId,
|
|
|
|
|
+ 'videoId': this.videoId,
|
|
|
|
|
+ 'currentTime': 0.0
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 跳转到指定秒
|
|
|
|
|
+ // dp.seek(100)
|
|
|
player.on('play', function() {
|
|
player.on('play', function() {
|
|
|
- playRecord1.currentTime = player.video.currentTime
|
|
|
|
|
- submitPlayRecord(playRecord1)
|
|
|
|
|
|
|
+ console.log('mp4Player 开始播放事件' + this.userId)
|
|
|
|
|
+ console.log(this.playRecord)
|
|
|
|
|
+ if (this.playRecord == null) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.playRecord.currentTime = player.video.currentTime
|
|
|
|
|
+ submitPlayRecord(this.playRecord)
|
|
|
.then(res => {
|
|
.then(res => {
|
|
|
- // eslint-disable-next-line no-empty
|
|
|
|
|
- if (res.code === 0) {
|
|
|
|
|
- } else {
|
|
|
|
|
- this.$notify({
|
|
|
|
|
- title: res.code,
|
|
|
|
|
- message: res.msg,
|
|
|
|
|
- type: 'warning',
|
|
|
|
|
- duration: 500
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .catch(error => {
|
|
|
|
|
|
|
+ }).catch(error => {
|
|
|
console.error(error.message)
|
|
console.error(error.message)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
player.on('pause', function() {
|
|
player.on('pause', function() {
|
|
|
- playRecord1.currentTime = player.video.currentTime
|
|
|
|
|
- submitPlayRecord(playRecord1)
|
|
|
|
|
|
|
+ if (this.playRecord == null) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.playRecord.currentTime = player.video.currentTime
|
|
|
|
|
+ submitPlayRecord(this.playRecord)
|
|
|
.then(res => {
|
|
.then(res => {
|
|
|
- // eslint-disable-next-line no-empty
|
|
|
|
|
- if (res.code === 0) {
|
|
|
|
|
- } else {
|
|
|
|
|
- this.$notify({
|
|
|
|
|
- title: res.code,
|
|
|
|
|
- message: res.msg,
|
|
|
|
|
- type: 'warning',
|
|
|
|
|
- duration: 500
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .catch(error => {
|
|
|
|
|
|
|
+ }).catch(error => {
|
|
|
console.error(error.message)
|
|
console.error(error.message)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
player.on('ended', function() {
|
|
player.on('ended', function() {
|
|
|
// TODO 当前视频播放完成后判断是否继续播放相关推荐中的视频
|
|
// TODO 当前视频播放完成后判断是否继续播放相关推荐中的视频
|
|
|
- playRecord1.currentTime = player.video.currentTime
|
|
|
|
|
- submitPlayRecord(playRecord1)
|
|
|
|
|
|
|
+ if (this.playRecord == null) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.playRecord.currentTime = player.video.currentTime
|
|
|
|
|
+ submitPlayRecord(this.playRecord)
|
|
|
.then(res => {
|
|
.then(res => {
|
|
|
- // eslint-disable-next-line no-empty
|
|
|
|
|
- if (res.code === 0) {
|
|
|
|
|
- } else {
|
|
|
|
|
- this.$notify({
|
|
|
|
|
- title: res.code,
|
|
|
|
|
- message: res.msg,
|
|
|
|
|
- type: 'warning',
|
|
|
|
|
- duration: 500
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .catch(error => {
|
|
|
|
|
|
|
+ }).catch(error => {
|
|
|
console.error(error.message)
|
|
console.error(error.message)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
player.on('seeking', function() {
|
|
player.on('seeking', function() {
|
|
|
- playRecord1.currentTime = player.video.currentTime
|
|
|
|
|
- submitPlayRecord(playRecord1)
|
|
|
|
|
|
|
+ if (this.playRecord == null) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.playRecord.currentTime = player.video.currentTime
|
|
|
|
|
+ submitPlayRecord(this.playRecord)
|
|
|
.then(res => {
|
|
.then(res => {
|
|
|
- // eslint-disable-next-line no-empty
|
|
|
|
|
- if (res.code === 0) {
|
|
|
|
|
- } else {
|
|
|
|
|
- this.$notify({
|
|
|
|
|
- title: res.code,
|
|
|
|
|
- message: res.msg,
|
|
|
|
|
- type: 'warning',
|
|
|
|
|
- duration: 500
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .catch(error => {
|
|
|
|
|
|
|
+ }).catch(error => {
|
|
|
console.error(error.message)
|
|
console.error(error.message)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
player.on('seeked', function() {
|
|
player.on('seeked', function() {
|
|
|
- playRecord1.currentTime = player.video.currentTime
|
|
|
|
|
- submitPlayRecord(playRecord1)
|
|
|
|
|
|
|
+ if (this.playRecord == null) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.playRecord.currentTime = player.video.currentTime
|
|
|
|
|
+ submitPlayRecord(this.playRecord)
|
|
|
.then(res => {
|
|
.then(res => {
|
|
|
- // eslint-disable-next-line no-empty
|
|
|
|
|
- if (res.code === 0) {
|
|
|
|
|
- } else {
|
|
|
|
|
- this.$notify({
|
|
|
|
|
- title: res.code,
|
|
|
|
|
- message: res.msg,
|
|
|
|
|
- type: 'warning',
|
|
|
|
|
- duration: 500
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .catch(error => {
|
|
|
|
|
|
|
+ }).catch(error => {
|
|
|
console.error(error.message)
|
|
console.error(error.message)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -201,22 +191,14 @@ export default {
|
|
|
player.on('progress', function() {
|
|
player.on('progress', function() {
|
|
|
console.log('i = ' + i)
|
|
console.log('i = ' + i)
|
|
|
if (i % 5 === 0) {
|
|
if (i % 5 === 0) {
|
|
|
- playRecord1.currentTime = player.video.currentTime
|
|
|
|
|
- submitPlayRecord(playRecord1)
|
|
|
|
|
|
|
+ if (this.playRecord == null) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.playRecord.currentTime = player.video.currentTime
|
|
|
|
|
+ submitPlayRecord(this.playRecord)
|
|
|
.then(res => {
|
|
.then(res => {
|
|
|
- // eslint-disable-next-line no-empty
|
|
|
|
|
- if (res.code === 0) {
|
|
|
|
|
- console.log('播放进度已发送: ' + i)
|
|
|
|
|
- } else {
|
|
|
|
|
- this.$notify({
|
|
|
|
|
- title: res.code,
|
|
|
|
|
- message: res.msg,
|
|
|
|
|
- type: 'warning',
|
|
|
|
|
- duration: 500
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .catch(error => {
|
|
|
|
|
|
|
+ }).catch(error => {
|
|
|
console.error(error.message)
|
|
console.error(error.message)
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
@@ -247,109 +229,68 @@ export default {
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- const playRecord1 = {
|
|
|
|
|
- 'userId': 110110,
|
|
|
|
|
- 'videoId': videoId,
|
|
|
|
|
- 'currentTime': 0.0
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
player.on('play', function() {
|
|
player.on('play', function() {
|
|
|
- playRecord1.currentTime = player.video.currentTime
|
|
|
|
|
- submitPlayRecord(playRecord1)
|
|
|
|
|
|
|
+ if (this.playRecord == null) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.playRecord.currentTime = player.video.currentTime
|
|
|
|
|
+ submitPlayRecord(this.playRecord)
|
|
|
.then(res => {
|
|
.then(res => {
|
|
|
- // eslint-disable-next-line no-empty
|
|
|
|
|
- if (res.code === 0) {
|
|
|
|
|
- } else {
|
|
|
|
|
- this.$notify({
|
|
|
|
|
- title: res.code,
|
|
|
|
|
- message: res.msg,
|
|
|
|
|
- type: 'warning',
|
|
|
|
|
- duration: 500
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .catch(error => {
|
|
|
|
|
|
|
+ }).catch(error => {
|
|
|
console.error(error.message)
|
|
console.error(error.message)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
player.on('pause', function() {
|
|
player.on('pause', function() {
|
|
|
- playRecord1.currentTime = player.video.currentTime
|
|
|
|
|
- submitPlayRecord(playRecord1)
|
|
|
|
|
|
|
+ if (this.playRecord == null) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.playRecord.currentTime = player.video.currentTime
|
|
|
|
|
+ submitPlayRecord(this.playRecord)
|
|
|
.then(res => {
|
|
.then(res => {
|
|
|
- // eslint-disable-next-line no-empty
|
|
|
|
|
- if (res.code === 0) {
|
|
|
|
|
- } else {
|
|
|
|
|
- this.$notify({
|
|
|
|
|
- title: res.code,
|
|
|
|
|
- message: res.msg,
|
|
|
|
|
- type: 'warning',
|
|
|
|
|
- duration: 500
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .catch(error => {
|
|
|
|
|
|
|
+ }).catch(error => {
|
|
|
console.error(error.message)
|
|
console.error(error.message)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
player.on('ended', function() {
|
|
player.on('ended', function() {
|
|
|
// TODO 当前视频播放完成后判断是否继续播放相关推荐中的视频
|
|
// TODO 当前视频播放完成后判断是否继续播放相关推荐中的视频
|
|
|
- playRecord1.currentTime = player.video.currentTime
|
|
|
|
|
- submitPlayRecord(playRecord1)
|
|
|
|
|
|
|
+ if (this.playRecord == null) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.playRecord.currentTime = player.video.currentTime
|
|
|
|
|
+ submitPlayRecord(this.playRecord)
|
|
|
.then(res => {
|
|
.then(res => {
|
|
|
- // eslint-disable-next-line no-empty
|
|
|
|
|
- if (res.code === 0) {
|
|
|
|
|
- } else {
|
|
|
|
|
- this.$notify({
|
|
|
|
|
- title: res.code,
|
|
|
|
|
- message: res.msg,
|
|
|
|
|
- type: 'warning',
|
|
|
|
|
- duration: 500
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .catch(error => {
|
|
|
|
|
|
|
+ }).catch(error => {
|
|
|
console.error(error.message)
|
|
console.error(error.message)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
player.on('seeking', function() {
|
|
player.on('seeking', function() {
|
|
|
- playRecord1.currentTime = player.video.currentTime
|
|
|
|
|
- submitPlayRecord(playRecord1)
|
|
|
|
|
|
|
+ if (this.playRecord == null) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.playRecord.currentTime = player.video.currentTime
|
|
|
|
|
+ submitPlayRecord(this.playRecord)
|
|
|
.then(res => {
|
|
.then(res => {
|
|
|
- // eslint-disable-next-line no-empty
|
|
|
|
|
- if (res.code === 0) {
|
|
|
|
|
- } else {
|
|
|
|
|
- this.$notify({
|
|
|
|
|
- title: res.code,
|
|
|
|
|
- message: res.msg,
|
|
|
|
|
- type: 'warning',
|
|
|
|
|
- duration: 500
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .catch(error => {
|
|
|
|
|
|
|
+ }).catch(error => {
|
|
|
console.error(error.message)
|
|
console.error(error.message)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
player.on('seeked', function() {
|
|
player.on('seeked', function() {
|
|
|
- playRecord1.currentTime = player.video.currentTime
|
|
|
|
|
- submitPlayRecord(playRecord1)
|
|
|
|
|
|
|
+ if (this.playRecord == null) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.playRecord.currentTime = player.video.currentTime
|
|
|
|
|
+ submitPlayRecord(this.playRecord)
|
|
|
.then(res => {
|
|
.then(res => {
|
|
|
- // eslint-disable-next-line no-empty
|
|
|
|
|
- if (res.code === 0) {
|
|
|
|
|
- } else {
|
|
|
|
|
- this.$notify({
|
|
|
|
|
- title: res.code,
|
|
|
|
|
- message: res.msg,
|
|
|
|
|
- type: 'warning',
|
|
|
|
|
- duration: 500
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .catch(error => {
|
|
|
|
|
|
|
+ }).catch(error => {
|
|
|
console.error(error.message)
|
|
console.error(error.message)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -358,22 +299,14 @@ export default {
|
|
|
player.on('progress', function() {
|
|
player.on('progress', function() {
|
|
|
console.log('i = ' + i)
|
|
console.log('i = ' + i)
|
|
|
if (i % 5 === 0) {
|
|
if (i % 5 === 0) {
|
|
|
- playRecord1.currentTime = player.video.currentTime
|
|
|
|
|
- submitPlayRecord(playRecord1)
|
|
|
|
|
|
|
+ if (this.playRecord == null) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.playRecord.currentTime = player.video.currentTime
|
|
|
|
|
+ submitPlayRecord(this.playRecord)
|
|
|
.then(res => {
|
|
.then(res => {
|
|
|
- // eslint-disable-next-line no-empty
|
|
|
|
|
- if (res.code === 0) {
|
|
|
|
|
- console.log('播放进度已发送: ' + i)
|
|
|
|
|
- } else {
|
|
|
|
|
- this.$notify({
|
|
|
|
|
- title: res.code,
|
|
|
|
|
- message: res.msg,
|
|
|
|
|
- type: 'warning',
|
|
|
|
|
- duration: 500
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .catch(error => {
|
|
|
|
|
|
|
+ }).catch(error => {
|
|
|
console.error(error.message)
|
|
console.error(error.message)
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|