|
@@ -1,5 +1,64 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <div id="dplayer" ref="dplayer" />
|
|
|
|
|
|
|
+ <div id="dplayer" ref="dplayer">
|
|
|
|
|
+ <v-dialog
|
|
|
|
|
+ v-model="permissionDialog"
|
|
|
|
|
+ max-width="290"
|
|
|
|
|
+ >
|
|
|
|
|
+ <v-card>
|
|
|
|
|
+ <v-card-title class="headline">VIP 观看</v-card-title>
|
|
|
|
|
+ <v-card-text>
|
|
|
|
|
+ <span>您还不是 VIP, 本视频仅供 VIP 观看</span>
|
|
|
|
|
+ </v-card-text>
|
|
|
|
|
+
|
|
|
|
|
+ <v-card-actions>
|
|
|
|
|
+ <v-spacer />
|
|
|
|
|
+ <v-btn
|
|
|
|
|
+ color="green darken-1"
|
|
|
|
|
+ text
|
|
|
|
|
+ @click="gotoHomePage"
|
|
|
|
|
+ >
|
|
|
|
|
+ 好的呢
|
|
|
|
|
+ </v-btn>
|
|
|
|
|
+ <v-btn
|
|
|
|
|
+ color="green darken-1"
|
|
|
|
|
+ text
|
|
|
|
|
+ @click="gotoVipPage"
|
|
|
|
|
+ >
|
|
|
|
|
+ 成为 VIP
|
|
|
|
|
+ </v-btn>
|
|
|
|
|
+ </v-card-actions>
|
|
|
|
|
+ </v-card>
|
|
|
|
|
+ </v-dialog>
|
|
|
|
|
+ <v-dialog
|
|
|
|
|
+ v-model="authCodeDialog"
|
|
|
|
|
+ max-width="290"
|
|
|
|
|
+ >
|
|
|
|
|
+ <v-form
|
|
|
|
|
+ ref="form"
|
|
|
|
|
+ lazy-validation
|
|
|
|
|
+ >
|
|
|
|
|
+ <v-text-field
|
|
|
|
|
+ v-model="authCode"
|
|
|
|
|
+ label="验证码"
|
|
|
|
|
+ required
|
|
|
|
|
+ />
|
|
|
|
|
+ <v-btn
|
|
|
|
|
+ color="success"
|
|
|
|
|
+ class="mr-4"
|
|
|
|
|
+ @click="submitAuthCode"
|
|
|
|
|
+ >
|
|
|
|
|
+ 提交
|
|
|
|
|
+ </v-btn>
|
|
|
|
|
+ <v-btn
|
|
|
|
|
+ color="error"
|
|
|
|
|
+ class="mr-4"
|
|
|
|
|
+ @click="cancelSubmitAuthCode"
|
|
|
|
|
+ >
|
|
|
|
|
+ 取消
|
|
|
|
|
+ </v-btn>
|
|
|
|
|
+ </v-form>
|
|
|
|
|
+ </v-dialog>
|
|
|
|
|
+ </div>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
@@ -12,9 +71,9 @@ const DPlayer = require('dplayer')
|
|
|
export default {
|
|
export default {
|
|
|
name: 'Play',
|
|
name: 'Play',
|
|
|
props: {
|
|
props: {
|
|
|
- videoCover: {
|
|
|
|
|
- type: String,
|
|
|
|
|
- default: () => ''
|
|
|
|
|
|
|
+ videoProp: {
|
|
|
|
|
+ type: Object,
|
|
|
|
|
+ default: () => null
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
data() {
|
|
data() {
|
|
@@ -23,45 +82,91 @@ export default {
|
|
|
dashjs,
|
|
dashjs,
|
|
|
flv,
|
|
flv,
|
|
|
DPlayer,
|
|
DPlayer,
|
|
|
- userId: 0,
|
|
|
|
|
- videoId: '',
|
|
|
|
|
- playRecord: null
|
|
|
|
|
|
|
+ userPermission: {
|
|
|
|
|
+ userId: -1,
|
|
|
|
|
+ vip: false
|
|
|
|
|
+ },
|
|
|
|
|
+ userId: -1,
|
|
|
|
|
+ playRecord: null,
|
|
|
|
|
+ getUrl: false,
|
|
|
|
|
+ permissionDialog: false,
|
|
|
|
|
+ authCodeDialog: false,
|
|
|
|
|
+ authCode: null
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- mounted() {
|
|
|
|
|
|
|
+ created() {
|
|
|
const userInfo = this.$store.state.user.userInfo
|
|
const userInfo = this.$store.state.user.userInfo
|
|
|
- if (userInfo != null) {
|
|
|
|
|
- this.userId = userInfo.userId
|
|
|
|
|
|
|
+ if (userInfo !== null) {
|
|
|
|
|
+ this.userPermission.userId = userInfo.userId
|
|
|
|
|
+ this.userPermission.vip = userInfo.vip
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.videoId = this.$route.params.id
|
|
|
|
|
- videoUrl(this.$route.params.id)
|
|
|
|
|
- .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'
|
|
|
|
|
|
|
+ const vidScope = this.videoProp.scope
|
|
|
|
|
+ if (vidScope === 1) {
|
|
|
|
|
+ this.getUrl = true
|
|
|
|
|
+ } else if (vidScope === 2) {
|
|
|
|
|
+ if (this.userPermission.vip) {
|
|
|
|
|
+ this.getUrl = true
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.permissionDialog = true
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (vidScope === 3) {
|
|
|
|
|
+ this.authCodeDialog = true
|
|
|
|
|
+ } else if (vidScope === 4) {
|
|
|
|
|
+ alert('私有视频, 只有本人可以观看')
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ mounted() {
|
|
|
|
|
+ const videoId = this.videoProp.videoId
|
|
|
|
|
+ if (this.getUrl) {
|
|
|
|
|
+ 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 类型无法识别')
|
|
|
}
|
|
}
|
|
|
- this.initMp4Player(this.userId, this.videoId, this.videoCover, urls)
|
|
|
|
|
- } else if (urlType === 'hls') {
|
|
|
|
|
- // this.initHlsPlayer(this.videoId, coverUrl, urls)
|
|
|
|
|
- } else if (urlType === 'dash') {
|
|
|
|
|
- // this.initDashPlayer(this.videoId, coverUrl, urls)
|
|
|
|
|
- } else if (urlType === 'flv') {
|
|
|
|
|
- // this.initFlvPlayer(this.videoId, coverUrl, urls)
|
|
|
|
|
} else {
|
|
} else {
|
|
|
- console.log('无法识别 url 类型')
|
|
|
|
|
|
|
+ console.error(res.msg)
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- console.error(res.msg)
|
|
|
|
|
- }
|
|
|
|
|
- }).catch(error => {
|
|
|
|
|
- console.error(error.message)
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ }).catch(error => {
|
|
|
|
|
+ console.error(error.message)
|
|
|
|
|
+ })*/
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
|
|
|
+ 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)
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
// TODO 获取弹幕配置,将 videoUrl 作为本函数的回调
|
|
// TODO 获取弹幕配置,将 videoUrl 作为本函数的回调
|
|
|
danmakuConfig() {
|
|
danmakuConfig() {
|
|
|
},
|
|
},
|
|
@@ -83,7 +188,7 @@ export default {
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
initMp4Player(userId, videoId, coverUrl, urls) {
|
|
initMp4Player(userId, videoId, coverUrl, urls) {
|
|
|
- const player = new DPlayer({
|
|
|
|
|
|
|
+ new DPlayer({
|
|
|
container: document.querySelector('#dplayer'),
|
|
container: document.querySelector('#dplayer'),
|
|
|
lang: 'zh-cn',
|
|
lang: 'zh-cn',
|
|
|
logo: '/logo.png',
|
|
logo: '/logo.png',
|
|
@@ -107,11 +212,11 @@ export default {
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- if (userId !== 0) {
|
|
|
|
|
|
|
+ /* if (userId !== 0) {
|
|
|
console.log('初始化 playRecord')
|
|
console.log('初始化 playRecord')
|
|
|
this.playRecord = {
|
|
this.playRecord = {
|
|
|
- 'userId': this.userId,
|
|
|
|
|
- 'videoId': this.videoId,
|
|
|
|
|
|
|
+ 'userId': this.userPermission.userId,
|
|
|
|
|
+ 'videoId': videoId,
|
|
|
'currentTime': 0.0
|
|
'currentTime': 0.0
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -119,7 +224,7 @@ export default {
|
|
|
// 跳转到指定秒
|
|
// 跳转到指定秒
|
|
|
// dp.seek(100)
|
|
// dp.seek(100)
|
|
|
player.on('play', function() {
|
|
player.on('play', function() {
|
|
|
- console.log('mp4Player 开始播放事件' + this.userId)
|
|
|
|
|
|
|
+ console.log('mp4Player 开始播放事件' + this.userPermission.userId)
|
|
|
console.log(this.playRecord)
|
|
console.log(this.playRecord)
|
|
|
if (this.playRecord == null) {
|
|
if (this.playRecord == null) {
|
|
|
return
|
|
return
|
|
@@ -202,10 +307,30 @@ export default {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
i++
|
|
i++
|
|
|
|
|
+ })*/
|
|
|
|
|
+ },
|
|
|
|
|
+ initFlvPlayer(videoId, coverUrl, videoUrl) {
|
|
|
|
|
+ new DPlayer({
|
|
|
|
|
+ container: document.getElementById('dplayer'),
|
|
|
|
|
+ video: {
|
|
|
|
|
+ url: videoUrl,
|
|
|
|
|
+ type: 'flv'
|
|
|
|
|
+ },
|
|
|
|
|
+ pluginOptions: {
|
|
|
|
|
+ flv: {
|
|
|
|
|
+ // refer to https://github.com/bilibili/flv.js/blob/master/docs/api.md#flvjscreateplayer
|
|
|
|
|
+ mediaDataSource: {
|
|
|
|
|
+ // mediaDataSource config
|
|
|
|
|
+ },
|
|
|
|
|
+ config: {
|
|
|
|
|
+ // config
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
initHlsPlayer(videoId, coverUrl, videoUrl) {
|
|
initHlsPlayer(videoId, coverUrl, videoUrl) {
|
|
|
- const player = new DPlayer({
|
|
|
|
|
|
|
+ new DPlayer({
|
|
|
container: document.querySelector('#dplayer'),
|
|
container: document.querySelector('#dplayer'),
|
|
|
lang: 'zh-cn',
|
|
lang: 'zh-cn',
|
|
|
autoplay: false,
|
|
autoplay: false,
|
|
@@ -221,142 +346,50 @@ export default {
|
|
|
maximum: 10000,
|
|
maximum: 10000,
|
|
|
api: '//api.reghao.cn/api/media/danmaku/',
|
|
api: '//api.reghao.cn/api/media/danmaku/',
|
|
|
token: 'bili',
|
|
token: 'bili',
|
|
|
- user: this.userId,
|
|
|
|
|
|
|
+ user: this.userPermission.userId,
|
|
|
videoId: videoId,
|
|
videoId: videoId,
|
|
|
bottom: '15%',
|
|
bottom: '15%',
|
|
|
unlimited: true
|
|
unlimited: true
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
- player.on('play', 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('pause', 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('ended', function() {
|
|
|
|
|
- // 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)
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- var i = 0
|
|
|
|
|
- player.on('progress', function() {
|
|
|
|
|
- console.log('i = ' + i)
|
|
|
|
|
- if (i % 5 === 0) {
|
|
|
|
|
- if (this.playRecord == null) {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- this.playRecord.currentTime = player.video.currentTime
|
|
|
|
|
- submitPlayRecord(this.playRecord)
|
|
|
|
|
- .then(res => {
|
|
|
|
|
- }).catch(error => {
|
|
|
|
|
- console.error(error.message)
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- i++
|
|
|
|
|
- })
|
|
|
|
|
},
|
|
},
|
|
|
initDashPlayer(videoId, coverUrl, videoUrl) {
|
|
initDashPlayer(videoId, coverUrl, videoUrl) {
|
|
|
- console.log('初始化 dash 播放器')
|
|
|
|
|
- const player = new DPlayer({
|
|
|
|
|
|
|
+ new DPlayer({
|
|
|
container: document.getElementById('dplayer'),
|
|
container: document.getElementById('dplayer'),
|
|
|
video: {
|
|
video: {
|
|
|
url: videoUrl,
|
|
url: videoUrl,
|
|
|
type: 'dash'
|
|
type: 'dash'
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
- console.log('dash 播放器初始化完成')
|
|
|
|
|
-
|
|
|
|
|
- player.on('play', function() {
|
|
|
|
|
- if (this.playRecord == null) {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ gotoHomePage() {
|
|
|
|
|
+ this.permissionDialog = false
|
|
|
|
|
+ if (this.$route.path === '/') {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ this.$router.push('/')
|
|
|
|
|
+ },
|
|
|
|
|
+ gotoVipPage() {
|
|
|
|
|
+ this.permissionDialog = false
|
|
|
|
|
+ if (this.$route.path === '/vip/plan') {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ this.$router.push('/vip/plan')
|
|
|
|
|
+ },
|
|
|
|
|
+ submitAuthCode() {
|
|
|
|
|
+ this.authCodeDialog = false
|
|
|
|
|
+ console.log('发送视频认证码')
|
|
|
|
|
+ console.log(this.videoProp.videoId)
|
|
|
|
|
+ console.log(this.authCode)
|
|
|
|
|
|
|
|
- this.playRecord.currentTime = player.video.currentTime
|
|
|
|
|
- submitPlayRecord(this.playRecord)
|
|
|
|
|
- .then(res => {
|
|
|
|
|
- }).catch(error => {
|
|
|
|
|
- console.error(error.message)
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ this.getVideoUrl(this.videoProp.videoId)
|
|
|
},
|
|
},
|
|
|
- initFlvPlayer(videoId, coverUrl, videoUrl) {
|
|
|
|
|
- console.log('初始化 flv 播放器')
|
|
|
|
|
- const dp = new DPlayer({
|
|
|
|
|
- container: document.getElementById('dplayer'),
|
|
|
|
|
- video: {
|
|
|
|
|
- url: videoUrl,
|
|
|
|
|
- type: 'flv'
|
|
|
|
|
- },
|
|
|
|
|
- pluginOptions: {
|
|
|
|
|
- flv: {
|
|
|
|
|
- // refer to https://github.com/bilibili/flv.js/blob/master/docs/api.md#flvjscreateplayer
|
|
|
|
|
- mediaDataSource: {
|
|
|
|
|
- // mediaDataSource config
|
|
|
|
|
- },
|
|
|
|
|
- config: {
|
|
|
|
|
- // config
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- console.log(dp.plugins.flv) // flv 实例
|
|
|
|
|
|
|
+ cancelSubmitAuthCode() {
|
|
|
|
|
+ this.authCodeDialog = false
|
|
|
|
|
+ if (this.$route.path === '/') {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ this.$router.push('/')
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|