|
@@ -4,18 +4,18 @@
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
import { videoUrl } from '@/api/media/video'
|
|
import { videoUrl } from '@/api/media/video'
|
|
|
-const Mp4Player = require('xgplayer')
|
|
|
|
|
-const HlsPlayer = require('xgplayer-hls.js')
|
|
|
|
|
-const DashPlayer = require('xgplayer-shaka')
|
|
|
|
|
-const FlvPlayer = require('xgplayer-flv.js')
|
|
|
|
|
|
|
+const hls = require('hls.js')
|
|
|
|
|
+const dashjs = require('dashjs')
|
|
|
|
|
+const flv = require('flv.js')
|
|
|
|
|
+const DPlayer = require('dplayer')
|
|
|
export default {
|
|
export default {
|
|
|
name: 'Play',
|
|
name: 'Play',
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
- Mp4Player,
|
|
|
|
|
- HlsPlayer,
|
|
|
|
|
- DashPlayer,
|
|
|
|
|
- FlvPlayer,
|
|
|
|
|
|
|
+ hls,
|
|
|
|
|
+ dashjs,
|
|
|
|
|
+ flv,
|
|
|
|
|
+ DPlayer,
|
|
|
videoId: ''
|
|
videoId: ''
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
@@ -34,29 +34,6 @@ export default {
|
|
|
// TODO 获取弹幕配置,将 videoUrl 作为本函数的回调
|
|
// TODO 获取弹幕配置,将 videoUrl 作为本函数的回调
|
|
|
danmakuConfig() {
|
|
danmakuConfig() {
|
|
|
},
|
|
},
|
|
|
- /* videoUrl() {
|
|
|
|
|
- fetch(`/api/media/video/url/${this.videoId}`, {
|
|
|
|
|
- headers: {
|
|
|
|
|
- 'Content-Type': 'application/json; charset=UTF-8',
|
|
|
|
|
- 'X-XSRF-TOKEN': this.$cookies.get('XSRF-TOKEN')
|
|
|
|
|
- },
|
|
|
|
|
- method: 'GET',
|
|
|
|
|
- credentials: 'include'
|
|
|
|
|
- }).then(response => response.json())
|
|
|
|
|
- .then(json => {
|
|
|
|
|
- if (json.code === 0) {
|
|
|
|
|
- var coverUrl = json.data.coverUrl
|
|
|
|
|
- var videoUrl = json.data.videoUrl
|
|
|
|
|
- this.initDplayer(this.videoId, coverUrl, videoUrl)
|
|
|
|
|
- } else {
|
|
|
|
|
- // TODO 显示错误信息
|
|
|
|
|
- // this.$router.push('/')
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .catch(e => {
|
|
|
|
|
- return null
|
|
|
|
|
- })
|
|
|
|
|
- },*/
|
|
|
|
|
getVideoUrl(videoId) {
|
|
getVideoUrl(videoId) {
|
|
|
videoUrl(videoId)
|
|
videoUrl(videoId)
|
|
|
.then(res => {
|
|
.then(res => {
|
|
@@ -90,112 +67,116 @@ export default {
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
initMp4Player(videoId, coverUrl, videoUrl) {
|
|
initMp4Player(videoId, coverUrl, videoUrl) {
|
|
|
- const player = new Mp4Player({
|
|
|
|
|
- id: 'dplayer',
|
|
|
|
|
|
|
+ const vidId = videoId
|
|
|
|
|
+ const player = new DPlayer({
|
|
|
|
|
+ container: document.querySelector('#dplayer'),
|
|
|
|
|
+ lang: 'zh-cn',
|
|
|
autoplay: false,
|
|
autoplay: false,
|
|
|
- keyShortcut: 'on',
|
|
|
|
|
- volume: 0.3,
|
|
|
|
|
- url: videoUrl,
|
|
|
|
|
- poster: coverUrl,
|
|
|
|
|
- playsinline: true,
|
|
|
|
|
- /* thumbnail: {
|
|
|
|
|
- pic_num: 44,
|
|
|
|
|
- width: 160,
|
|
|
|
|
- height: 90,
|
|
|
|
|
- col: 10,
|
|
|
|
|
- row: 10,
|
|
|
|
|
- urls: ['//lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/byted-player-videos/1.0.0/xgplayer-demo-thumbnail.jpg']
|
|
|
|
|
- },*/
|
|
|
|
|
- danmu: {
|
|
|
|
|
- comments: [
|
|
|
|
|
- {
|
|
|
|
|
- duration: 15000,
|
|
|
|
|
- id: '1',
|
|
|
|
|
- start: 3000,
|
|
|
|
|
- txt: '长弹幕长弹幕长弹幕长弹幕长弹幕',
|
|
|
|
|
- style: { // 弹幕自定义样式
|
|
|
|
|
- color: '#ff9500',
|
|
|
|
|
- fontSize: '20px',
|
|
|
|
|
- border: 'solid 1px #ff9500',
|
|
|
|
|
- borderRadius: '50px',
|
|
|
|
|
- padding: '5px 11px',
|
|
|
|
|
- backgroundColor: 'rgba(255, 255, 255, 0.1)'
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- ],
|
|
|
|
|
- area: {
|
|
|
|
|
- start: 0,
|
|
|
|
|
- end: 1
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ screenshot: true,
|
|
|
|
|
+ video: {
|
|
|
|
|
+ pic: coverUrl,
|
|
|
|
|
+ url: videoUrl,
|
|
|
|
|
+ type: 'auto'
|
|
|
|
|
+ // type: 'dash'
|
|
|
},
|
|
},
|
|
|
- width: 1200,
|
|
|
|
|
- height: 480
|
|
|
|
|
|
|
+ logo: '/logo.png',
|
|
|
|
|
+ danmaku: {
|
|
|
|
|
+ id: videoId,
|
|
|
|
|
+ maximum: 10000,
|
|
|
|
|
+ api: '/api/media/danmaku/',
|
|
|
|
|
+ token: 'hertube',
|
|
|
|
|
+ user: this.userId,
|
|
|
|
|
+ bottom: '15%',
|
|
|
|
|
+ unlimited: true
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ // 跳转到指定秒
|
|
|
|
|
+ // dp.seek(100)
|
|
|
|
|
+
|
|
|
player.on('play', function() {
|
|
player.on('play', function() {
|
|
|
- console.log(videoId + ' 视频播放')
|
|
|
|
|
|
|
+ console.log(vidId + ' 播放开始' + player.video.currentTime)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
player.on('pause', function() {
|
|
player.on('pause', function() {
|
|
|
- console.log(videoId + ' 视频暂停')
|
|
|
|
|
|
|
+ console.log(vidId + ' 播放暂停' + player.video.currentTime)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
player.on('ended', function() {
|
|
player.on('ended', function() {
|
|
|
- console.log(videoId + ' 视频结束')
|
|
|
|
|
- })
|
|
|
|
|
- },
|
|
|
|
|
- initHlsPlayer(videoId, coverUrl, videoUrl) {
|
|
|
|
|
- const player = new HlsPlayer({
|
|
|
|
|
- id: 'dplayer',
|
|
|
|
|
- url: videoUrl,
|
|
|
|
|
- poster: coverUrl,
|
|
|
|
|
- autoplay: false,
|
|
|
|
|
- playsinline: true,
|
|
|
|
|
- width: 1200,
|
|
|
|
|
- height: 480
|
|
|
|
|
|
|
+ // TODO 当前视频播放完成后判断是否继续播放相关推荐中的视频
|
|
|
|
|
+ console.log(vidId + ' 播放结束' + player.video.currentTime)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- player.on('play', function() {
|
|
|
|
|
- console.log(videoId + ' 视频播放')
|
|
|
|
|
- })
|
|
|
|
|
- },
|
|
|
|
|
- initDashPlayer(videoId, coverUrl, videoUrl) {
|
|
|
|
|
- const player = new DashPlayer({
|
|
|
|
|
- id: 'dplayer',
|
|
|
|
|
- url: videoUrl,
|
|
|
|
|
- poster: coverUrl,
|
|
|
|
|
- ignores: ['error'],
|
|
|
|
|
- playsinline: true,
|
|
|
|
|
- width: 1200,
|
|
|
|
|
- height: 480
|
|
|
|
|
|
|
+ player.on('seeking', function() {
|
|
|
|
|
+ console.log(vidId + ' seeking 事件 ' + player.video.currentTime)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- player.on('play', function() {
|
|
|
|
|
- console.log(videoId + ' 视频播放')
|
|
|
|
|
|
|
+ player.on('seeked', function() {
|
|
|
|
|
+ console.log(vidId + ' seeked 事件' + player.video.currentTime)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- player.on('timeupdate', function() {
|
|
|
|
|
- console.log(videoId + ' 播放时间改变')
|
|
|
|
|
|
|
+ const interval = 5
|
|
|
|
|
+ var i = 0
|
|
|
|
|
+ player.on('progress', function() {
|
|
|
|
|
+ console.log('i = ' + i)
|
|
|
|
|
+ if (i % interval === 0) {
|
|
|
|
|
+ // TODO 每 5s 向后端报告一次播放进度
|
|
|
|
|
+ console.log(vidId + ' 播放进度 ' + player.video.currentTime)
|
|
|
|
|
+ }
|
|
|
|
|
+ i++
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
- initFlvPlayer(videoId, coverUrl, videoUrl) {
|
|
|
|
|
- const player = new FlvPlayer({
|
|
|
|
|
- id: 'dplayer',
|
|
|
|
|
- url: videoUrl,
|
|
|
|
|
- poster: coverUrl,
|
|
|
|
|
- isLive: true,
|
|
|
|
|
- playsinline: true,
|
|
|
|
|
- width: 1200,
|
|
|
|
|
- height: 480
|
|
|
|
|
|
|
+ initHlsPlayer(videoId, coverUrl, videoUrl) {
|
|
|
|
|
+ new DPlayer({
|
|
|
|
|
+ container: document.querySelector('#dplayer'),
|
|
|
|
|
+ lang: 'zh-cn',
|
|
|
|
|
+ autoplay: false,
|
|
|
|
|
+ screenshot: true,
|
|
|
|
|
+ video: {
|
|
|
|
|
+ pic: coverUrl,
|
|
|
|
|
+ url: videoUrl,
|
|
|
|
|
+ type: 'hls'
|
|
|
|
|
+ },
|
|
|
|
|
+ logo: '/logo.png'
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
- player.on('play', function() {
|
|
|
|
|
- console.log(videoId + ' 视频播放')
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ initDashPlayer(videoId, coverUrl, videoUrl) {
|
|
|
|
|
+ console.log('初始化 dash 播放器')
|
|
|
|
|
+ const dp = new DPlayer({
|
|
|
|
|
+ container: document.getElementById('dplayer'),
|
|
|
|
|
+ video: {
|
|
|
|
|
+ url: videoUrl,
|
|
|
|
|
+ type: 'dash'
|
|
|
|
|
+ },
|
|
|
|
|
+ pluginOptions: {
|
|
|
|
|
+ dash: {
|
|
|
|
|
+ // dash config
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
- player.on('timeupdate', function() {
|
|
|
|
|
- console.log(videoId + ' 播放时间改变')
|
|
|
|
|
|
|
+ console.log(dp.plugins.dash)
|
|
|
|
|
+ },
|
|
|
|
|
+ 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 实例
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|