|
@@ -62,13 +62,13 @@
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
-import { videoUrl, submitPlayRecord } from '@/api/media/video'
|
|
|
|
|
|
|
+import { videoUrl } from '@/api/media/video'
|
|
|
import SocketInstance from '@/utils/ws/socket-instance'
|
|
import SocketInstance from '@/utils/ws/socket-instance'
|
|
|
|
|
|
|
|
|
|
+const DPlayer = require('dplayer')
|
|
|
|
|
+const flv = require('flv.js')
|
|
|
const hls = require('hls.js')
|
|
const hls = require('hls.js')
|
|
|
const dashjs = require('dashjs')
|
|
const dashjs = require('dashjs')
|
|
|
-const flv = require('flv.js')
|
|
|
|
|
-const DPlayer = require('dplayer')
|
|
|
|
|
|
|
|
|
|
export default {
|
|
export default {
|
|
|
name: 'Play',
|
|
name: 'Play',
|
|
@@ -123,27 +123,6 @@ export default {
|
|
|
const videoId = this.videoProp.videoId
|
|
const videoId = this.videoProp.videoId
|
|
|
if (this.getUrl) {
|
|
if (this.getUrl) {
|
|
|
this.getVideoUrl(videoId)
|
|
this.getVideoUrl(videoId)
|
|
|
- /* videoUrl(videoId)
|
|
|
|
|
- .then(res => {
|
|
|
|
|
- if (res.code === 0) {
|
|
|
|
|
- const urlType = res.data.type
|
|
|
|
|
- if (urlType === 'mp4') {
|
|
|
|
|
- const urls = res.data.urls
|
|
|
|
|
- for (const url of urls) {
|
|
|
|
|
- url.type = 'normal'
|
|
|
|
|
- }
|
|
|
|
|
- this.initMp4Player(this.userPermission.userId, videoId, this.videoProp.coverUrl, urls)
|
|
|
|
|
- } else if (urlType === 'flv') {
|
|
|
|
|
- // this.initFlvPlayer(videoId, coverUrl, urls)
|
|
|
|
|
- } else {
|
|
|
|
|
- alert('url 类型无法识别')
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- console.error(res.msg)
|
|
|
|
|
- }
|
|
|
|
|
- }).catch(error => {
|
|
|
|
|
- console.error(error.message)
|
|
|
|
|
- })*/
|
|
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
@@ -157,7 +136,7 @@ export default {
|
|
|
for (const url of urls) {
|
|
for (const url of urls) {
|
|
|
url.type = 'normal'
|
|
url.type = 'normal'
|
|
|
}
|
|
}
|
|
|
- this.initMp4Player(this.userPermission.userId, videoId, this.videoProp.coverUrl, urls)
|
|
|
|
|
|
|
+ this.initMp4Player(this.userPermission.userId, videoId, this.videoProp.coverUrl, urls, 0)
|
|
|
} else if (urlType === 'flv') {
|
|
} else if (urlType === 'flv') {
|
|
|
// this.initFlvPlayer(videoId, coverUrl, urls)
|
|
// this.initFlvPlayer(videoId, coverUrl, urls)
|
|
|
} else {
|
|
} else {
|
|
@@ -173,24 +152,7 @@ export default {
|
|
|
// TODO 获取弹幕配置,将 videoUrl 作为本函数的回调
|
|
// TODO 获取弹幕配置,将 videoUrl 作为本函数的回调
|
|
|
danmakuConfig() {
|
|
danmakuConfig() {
|
|
|
},
|
|
},
|
|
|
- submitVideoPlayRecord(currentTime) {
|
|
|
|
|
- if (this.playRecord == null) {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- this.playRecord.currentTime = currentTime
|
|
|
|
|
- submitPlayRecord(this.playRecord)
|
|
|
|
|
- .then(res => {
|
|
|
|
|
- if (res.code === 0) {
|
|
|
|
|
- console.log('播放进度已发送')
|
|
|
|
|
- } else {
|
|
|
|
|
- console.error(res.msg)
|
|
|
|
|
- }
|
|
|
|
|
- }).catch(error => {
|
|
|
|
|
- console.error(error.message)
|
|
|
|
|
- })
|
|
|
|
|
- },
|
|
|
|
|
- initMp4Player(userId, videoId, coverUrl, urls) {
|
|
|
|
|
|
|
+ initMp4Player(userId, videoId, coverUrl, urls, pos) {
|
|
|
const player = new DPlayer({
|
|
const player = new DPlayer({
|
|
|
container: document.querySelector('#dplayer'),
|
|
container: document.querySelector('#dplayer'),
|
|
|
lang: 'zh-cn',
|
|
lang: 'zh-cn',
|
|
@@ -215,78 +177,16 @@ export default {
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- // 跳转到指定秒
|
|
|
|
|
- // dp.seek(100)
|
|
|
|
|
- /* player.on('play', function() {
|
|
|
|
|
- console.log('mp4Player 开始播放事件' + this.userPermission.userId)
|
|
|
|
|
- console.log(this.playRecord)
|
|
|
|
|
- if (this.playRecord == null) {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- this.playRecord.currentTime = player.video.currentTime
|
|
|
|
|
- submitPlayRecord(this.playRecord)
|
|
|
|
|
- .then(res => {
|
|
|
|
|
- }).catch(error => {
|
|
|
|
|
- console.error(error.message)
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- player.on('pause', function() {
|
|
|
|
|
- if (this.playRecord == null) {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 跳转到上次看到的位置
|
|
|
|
|
+ player.seek(pos)
|
|
|
|
|
|
|
|
- this.playRecord.currentTime = player.video.currentTime
|
|
|
|
|
- submitPlayRecord(this.playRecord)
|
|
|
|
|
- .then(res => {
|
|
|
|
|
- }).catch(error => {
|
|
|
|
|
- console.error(error.message)
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ player.on('progress', function() {
|
|
|
|
|
+ SocketInstance.send({ userId: userId, videoId: videoId, currentTime: player.video.currentTime })
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
player.on('ended', function() {
|
|
player.on('ended', function() {
|
|
|
// TODO 当前视频播放完成后判断是否继续播放相关推荐中的视频
|
|
// TODO 当前视频播放完成后判断是否继续播放相关推荐中的视频
|
|
|
- if (this.playRecord == null) {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- this.playRecord.currentTime = player.video.currentTime
|
|
|
|
|
- submitPlayRecord(this.playRecord)
|
|
|
|
|
- .then(res => {
|
|
|
|
|
- }).catch(error => {
|
|
|
|
|
- console.error(error.message)
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- player.on('seeking', function() {
|
|
|
|
|
- if (this.playRecord == null) {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- this.playRecord.currentTime = player.video.currentTime
|
|
|
|
|
- submitPlayRecord(this.playRecord)
|
|
|
|
|
- .then(res => {
|
|
|
|
|
- }).catch(error => {
|
|
|
|
|
- console.error(error.message)
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- player.on('seeked', function() {
|
|
|
|
|
- if (this.playRecord == null) {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- this.playRecord.currentTime = player.video.currentTime
|
|
|
|
|
- submitPlayRecord(this.playRecord)
|
|
|
|
|
- .then(res => {
|
|
|
|
|
- }).catch(error => {
|
|
|
|
|
- console.error(error.message)
|
|
|
|
|
- })
|
|
|
|
|
- })*/
|
|
|
|
|
-
|
|
|
|
|
- player.on('progress', function() {
|
|
|
|
|
- SocketInstance.send({ userId: userId, videoId: videoId, currentTime: player.video.currentTime })
|
|
|
|
|
|
|
+ console.log('视频播放完成')
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
initFlvPlayer(videoId, coverUrl, videoUrl) {
|
|
initFlvPlayer(videoId, coverUrl, videoUrl) {
|
|
@@ -376,7 +276,4 @@ export default {
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
<style>
|
|
|
-#dplayer {
|
|
|
|
|
- height: 500px;
|
|
|
|
|
-}
|
|
|
|
|
</style>
|
|
</style>
|