|
|
@@ -11,6 +11,12 @@ const DPlayer = require('dplayer')
|
|
|
|
|
|
export default {
|
|
|
name: 'Play',
|
|
|
+ props: {
|
|
|
+ videoCover: {
|
|
|
+ type: String,
|
|
|
+ default: () => ''
|
|
|
+ }
|
|
|
+ },
|
|
|
data() {
|
|
|
return {
|
|
|
hls,
|
|
|
@@ -32,18 +38,19 @@ export default {
|
|
|
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
|
|
|
+ const urlType = res.data.type
|
|
|
if (urlType === 'mp4') {
|
|
|
- this.initMp4Player(this.userId, this.videoId, coverUrl, videoUrl)
|
|
|
+ const urls = res.data.urls
|
|
|
+ for (const url of urls) {
|
|
|
+ url.type = 'normal'
|
|
|
+ }
|
|
|
+ this.initMp4Player(this.userId, this.videoId, this.videoCover, urls)
|
|
|
} else if (urlType === 'hls') {
|
|
|
- this.initHlsPlayer(this.videoId, coverUrl, videoUrl)
|
|
|
+ // this.initHlsPlayer(this.videoId, coverUrl, urls)
|
|
|
} else if (urlType === 'dash') {
|
|
|
- this.initDashPlayer(this.videoId, coverUrl, videoUrl)
|
|
|
+ // this.initDashPlayer(this.videoId, coverUrl, urls)
|
|
|
} else if (urlType === 'flv') {
|
|
|
- this.initFlvPlayer(this.videoId, coverUrl, videoUrl)
|
|
|
+ // this.initFlvPlayer(this.videoId, coverUrl, urls)
|
|
|
} else {
|
|
|
console.log('无法识别 url 类型')
|
|
|
}
|
|
|
@@ -75,17 +82,19 @@ export default {
|
|
|
console.error(error.message)
|
|
|
})
|
|
|
},
|
|
|
- initMp4Player(userId, videoId, coverUrl, videoUrl) {
|
|
|
+ initMp4Player(userId, videoId, coverUrl, urls) {
|
|
|
const player = new DPlayer({
|
|
|
container: document.querySelector('#dplayer'),
|
|
|
lang: 'zh-cn',
|
|
|
logo: '/logo.png',
|
|
|
autoplay: false,
|
|
|
- screenshot: true,
|
|
|
+ screenshot: false,
|
|
|
video: {
|
|
|
pic: coverUrl,
|
|
|
- url: videoUrl,
|
|
|
- type: 'auto'
|
|
|
+ defaultQuality: 0,
|
|
|
+ quality: urls
|
|
|
+ // url: videoUrl
|
|
|
+ // type: 'auto',
|
|
|
},
|
|
|
danmaku: {
|
|
|
id: videoId,
|