|
@@ -3,7 +3,7 @@
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
-import { videoUrl } from '@/api/media/video'
|
|
|
|
|
|
|
+import { videoUrl, submitPlayRecord } from '@/api/media/video'
|
|
|
const hls = require('hls.js')
|
|
const hls = require('hls.js')
|
|
|
const dashjs = require('dashjs')
|
|
const dashjs = require('dashjs')
|
|
|
const flv = require('flv.js')
|
|
const flv = require('flv.js')
|
|
@@ -16,6 +16,7 @@ export default {
|
|
|
dashjs,
|
|
dashjs,
|
|
|
flv,
|
|
flv,
|
|
|
DPlayer,
|
|
DPlayer,
|
|
|
|
|
+ userId: 0,
|
|
|
videoId: ''
|
|
videoId: ''
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
@@ -24,50 +25,45 @@ export default {
|
|
|
if (userInfo != null) {
|
|
if (userInfo != null) {
|
|
|
this.userId = userInfo.id.toString()
|
|
this.userId = userInfo.id.toString()
|
|
|
} else {
|
|
} else {
|
|
|
- this.userId = 111222333
|
|
|
|
|
|
|
+ this.userId = 110101
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
this.videoId = this.$route.params.id
|
|
this.videoId = this.$route.params.id
|
|
|
- this.getVideoUrl(this.videoId)
|
|
|
|
|
|
|
+ videoUrl(this.$route.params.id)
|
|
|
|
|
+ .then(res => {
|
|
|
|
|
+ if (res.code === 0) {
|
|
|
|
|
+ // TODO 返回一个 dplayer 播放器对象,包含一些常用的属性
|
|
|
|
|
+ var coverUrl = res.data.coverUrl
|
|
|
|
|
+ var videoUrl = res.data.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 if (urlType === 'flv') {
|
|
|
|
|
+ this.initFlvPlayer(this.videoId, coverUrl, videoUrl)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.log('无法识别 url 类型')
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.$notify({
|
|
|
|
|
+ title: res.code,
|
|
|
|
|
+ message: res.msg,
|
|
|
|
|
+ type: 'warning',
|
|
|
|
|
+ duration: 500
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(error => {
|
|
|
|
|
+ console.error(error.message)
|
|
|
|
|
+ })
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
|
// TODO 获取弹幕配置,将 videoUrl 作为本函数的回调
|
|
// TODO 获取弹幕配置,将 videoUrl 作为本函数的回调
|
|
|
danmakuConfig() {
|
|
danmakuConfig() {
|
|
|
},
|
|
},
|
|
|
- getVideoUrl(videoId) {
|
|
|
|
|
- videoUrl(videoId)
|
|
|
|
|
- .then(res => {
|
|
|
|
|
- if (res.code === 0) {
|
|
|
|
|
- // TODO 返回一个 dplayer 播放器对象,包含一些常用的属性
|
|
|
|
|
- var coverUrl = res.data.coverUrl
|
|
|
|
|
- var videoUrl = res.data.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 if (urlType === 'flv') {
|
|
|
|
|
- this.initFlvPlayer(this.videoId, coverUrl, videoUrl)
|
|
|
|
|
- } else {
|
|
|
|
|
- console.log('无法识别 url 类型')
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- this.$notify({
|
|
|
|
|
- title: res.code,
|
|
|
|
|
- message: res.msg,
|
|
|
|
|
- type: 'warning',
|
|
|
|
|
- duration: 500
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .catch(error => {
|
|
|
|
|
- console.error(error.message)
|
|
|
|
|
- })
|
|
|
|
|
- },
|
|
|
|
|
initMp4Player(videoId, coverUrl, videoUrl) {
|
|
initMp4Player(videoId, coverUrl, videoUrl) {
|
|
|
- const vidId = videoId
|
|
|
|
|
const player = new DPlayer({
|
|
const player = new DPlayer({
|
|
|
container: document.querySelector('#dplayer'),
|
|
container: document.querySelector('#dplayer'),
|
|
|
lang: 'zh-cn',
|
|
lang: 'zh-cn',
|
|
@@ -83,7 +79,7 @@ export default {
|
|
|
danmaku: {
|
|
danmaku: {
|
|
|
id: videoId,
|
|
id: videoId,
|
|
|
maximum: 10000,
|
|
maximum: 10000,
|
|
|
- api: '/api/media/danmaku/',
|
|
|
|
|
|
|
+ api: 'api.reghao.cn/api/media/danmaku/',
|
|
|
token: 'hertube',
|
|
token: 'hertube',
|
|
|
user: this.userId,
|
|
user: this.userId,
|
|
|
bottom: '15%',
|
|
bottom: '15%',
|
|
@@ -95,24 +91,24 @@ export default {
|
|
|
// dp.seek(100)
|
|
// dp.seek(100)
|
|
|
|
|
|
|
|
player.on('play', function() {
|
|
player.on('play', function() {
|
|
|
- console.log(vidId + ' 播放开始' + player.video.currentTime)
|
|
|
|
|
|
|
+ console.log(videoId + ' 播放开始' + player.video.currentTime)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
player.on('pause', function() {
|
|
player.on('pause', function() {
|
|
|
- console.log(vidId + ' 播放暂停' + player.video.currentTime)
|
|
|
|
|
|
|
+ console.log(videoId + ' 播放暂停' + player.video.currentTime)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
player.on('ended', function() {
|
|
player.on('ended', function() {
|
|
|
// TODO 当前视频播放完成后判断是否继续播放相关推荐中的视频
|
|
// TODO 当前视频播放完成后判断是否继续播放相关推荐中的视频
|
|
|
- console.log(vidId + ' 播放结束' + player.video.currentTime)
|
|
|
|
|
|
|
+ console.log(videoId + ' 播放结束' + player.video.currentTime)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
player.on('seeking', function() {
|
|
player.on('seeking', function() {
|
|
|
- console.log(vidId + ' seeking 事件 ' + player.video.currentTime)
|
|
|
|
|
|
|
+ console.log(videoId + ' seeking 事件 ' + player.video.currentTime)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
player.on('seeked', function() {
|
|
player.on('seeked', function() {
|
|
|
- console.log(vidId + ' seeked 事件' + player.video.currentTime)
|
|
|
|
|
|
|
+ console.log(videoId + ' seeked 事件' + player.video.currentTime)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
const interval = 5
|
|
const interval = 5
|
|
@@ -121,13 +117,13 @@ export default {
|
|
|
console.log('i = ' + i)
|
|
console.log('i = ' + i)
|
|
|
if (i % interval === 0) {
|
|
if (i % interval === 0) {
|
|
|
// TODO 每 5s 向后端报告一次播放进度
|
|
// TODO 每 5s 向后端报告一次播放进度
|
|
|
- console.log(vidId + ' 播放进度 ' + player.video.currentTime)
|
|
|
|
|
|
|
+ console.log(videoId + ' 播放进度 ' + player.video.currentTime)
|
|
|
}
|
|
}
|
|
|
i++
|
|
i++
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
initHlsPlayer(videoId, coverUrl, videoUrl) {
|
|
initHlsPlayer(videoId, coverUrl, videoUrl) {
|
|
|
- new DPlayer({
|
|
|
|
|
|
|
+ const player = new DPlayer({
|
|
|
container: document.querySelector('#dplayer'),
|
|
container: document.querySelector('#dplayer'),
|
|
|
lang: 'zh-cn',
|
|
lang: 'zh-cn',
|
|
|
autoplay: false,
|
|
autoplay: false,
|
|
@@ -137,7 +133,149 @@ export default {
|
|
|
url: videoUrl,
|
|
url: videoUrl,
|
|
|
type: 'hls'
|
|
type: 'hls'
|
|
|
},
|
|
},
|
|
|
- logo: '/logo.png'
|
|
|
|
|
|
|
+ logo: '/logo.png',
|
|
|
|
|
+ danmaku: {
|
|
|
|
|
+ id: videoId,
|
|
|
|
|
+ maximum: 10000,
|
|
|
|
|
+ api: '//api.reghao.cn/api/media/danmaku/',
|
|
|
|
|
+ token: 'hertube',
|
|
|
|
|
+ user: this.userId,
|
|
|
|
|
+ bottom: '15%',
|
|
|
|
|
+ unlimited: true
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ const playRecord1 = {
|
|
|
|
|
+ 'userId': 110110,
|
|
|
|
|
+ 'videoId': videoId,
|
|
|
|
|
+ 'currentTime': 0.0
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ player.on('play', function() {
|
|
|
|
|
+ playRecord1.currentTime = player.video.currentTime
|
|
|
|
|
+ submitPlayRecord(playRecord1)
|
|
|
|
|
+ .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 => {
|
|
|
|
|
+ console.error(error.message)
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ player.on('pause', function() {
|
|
|
|
|
+ playRecord1.currentTime = player.video.currentTime
|
|
|
|
|
+ submitPlayRecord(playRecord1)
|
|
|
|
|
+ .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 => {
|
|
|
|
|
+ console.error(error.message)
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ player.on('ended', function() {
|
|
|
|
|
+ // TODO 当前视频播放完成后判断是否继续播放相关推荐中的视频
|
|
|
|
|
+ playRecord1.currentTime = player.video.currentTime
|
|
|
|
|
+ submitPlayRecord(playRecord1)
|
|
|
|
|
+ .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 => {
|
|
|
|
|
+ console.error(error.message)
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ player.on('seeking', function() {
|
|
|
|
|
+ playRecord1.currentTime = player.video.currentTime
|
|
|
|
|
+ submitPlayRecord(playRecord1)
|
|
|
|
|
+ .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 => {
|
|
|
|
|
+ console.error(error.message)
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ player.on('seeked', function() {
|
|
|
|
|
+ playRecord1.currentTime = player.video.currentTime
|
|
|
|
|
+ submitPlayRecord(playRecord1)
|
|
|
|
|
+ .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 => {
|
|
|
|
|
+ console.error(error.message)
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ var i = 0
|
|
|
|
|
+ player.on('progress', function() {
|
|
|
|
|
+ console.log('i = ' + i)
|
|
|
|
|
+ if (i % 5 === 0) {
|
|
|
|
|
+ playRecord1.currentTime = player.video.currentTime
|
|
|
|
|
+ submitPlayRecord(playRecord1)
|
|
|
|
|
+ .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 => {
|
|
|
|
|
+ console.error(error.message)
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ i++
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
initDashPlayer(videoId, coverUrl, videoUrl) {
|
|
initDashPlayer(videoId, coverUrl, videoUrl) {
|