|
|
@@ -4,7 +4,6 @@
|
|
|
|
|
|
<script>
|
|
|
import { videoUrl } from '@/api/video'
|
|
|
-import SocketInstance from '@/utils/ws/socket-instance'
|
|
|
|
|
|
import flvjs from 'flv.js'
|
|
|
import DPlayer from 'dplayer'
|
|
|
@@ -31,38 +30,16 @@ export default {
|
|
|
created() {
|
|
|
},
|
|
|
mounted() {
|
|
|
- // SocketInstance.connect()
|
|
|
-
|
|
|
const videoId = this.videoProp.videoId
|
|
|
if (this.getUrl) {
|
|
|
- // this.getVideoUrl(videoId)
|
|
|
const url = 'https://disk.reghao.cn/live/cam1'
|
|
|
this.initFlvPlayer(videoId, this.videoProp.coverUrl, url)
|
|
|
}
|
|
|
},
|
|
|
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'
|
|
|
- }
|
|
|
- const autoPlay = false
|
|
|
- this.initMp4Player(this.videoProp.userId, videoId, this.videoProp.coverUrl, urls, res.data.currentTime, autoPlay)
|
|
|
- } else if (urlType === 'flv') {
|
|
|
- const urls = res.data.urls
|
|
|
- const url = urls[0].url
|
|
|
- this.initFlvPlayer(videoId, this.videoProp.coverUrl, url)
|
|
|
- } else {
|
|
|
- this.$notify.error({
|
|
|
- message: '视频 url 类型不合法',
|
|
|
- type: 'warning',
|
|
|
- duration: 3000
|
|
|
- })
|
|
|
- }
|
|
|
+ videoUrl(videoId).then(resp => {
|
|
|
+ if (resp.code === 0) {
|
|
|
} else {
|
|
|
this.$notify.error({
|
|
|
message: '视频 url 获取失败',
|
|
|
@@ -72,67 +49,14 @@ export default {
|
|
|
}
|
|
|
}).catch(error => {
|
|
|
this.$notify.error({
|
|
|
- message: '视频 url 获取失败',
|
|
|
+ message: error.message,
|
|
|
type: 'warning',
|
|
|
duration: 3000
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
- danmakuConfig() {
|
|
|
- // TODO 获取弹幕配置,将 videoUrl 作为本函数的回调
|
|
|
- },
|
|
|
- initMp4Player(userId, videoId, coverUrl, urls, pos, autoPlay) {
|
|
|
- const player = new DPlayer({
|
|
|
- container: document.querySelector('#dplayer'),
|
|
|
- lang: 'zh-cn',
|
|
|
- logo: '/logo.png',
|
|
|
- screenshot: false,
|
|
|
- autoplay: autoPlay,
|
|
|
- volume: 0.1,
|
|
|
- mutex: true,
|
|
|
- video: {
|
|
|
- pic: coverUrl,
|
|
|
- defaultQuality: 0,
|
|
|
- quality: urls
|
|
|
- },
|
|
|
- danmaku: {
|
|
|
- id: videoId,
|
|
|
- maximum: 10000,
|
|
|
- api: this.danmaku.api,
|
|
|
- token: this.danmaku.token,
|
|
|
- user: userId,
|
|
|
- bottom: '15%',
|
|
|
- unlimited: true
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- // 设置音量
|
|
|
- //player.volume(0.1, true, false)
|
|
|
- // 跳转到上次看到的位置
|
|
|
- player.seek(pos)
|
|
|
-
|
|
|
- /* 事件绑定 */
|
|
|
- player.on('progress', function() {
|
|
|
- // SocketInstance.send({ videoId: videoId, currentTime: player.video.currentTime })
|
|
|
- })
|
|
|
-
|
|
|
- player.on('ended', () => {
|
|
|
- // SocketInstance.send({ videoId: videoId, currentTime: player.video.currentTime })
|
|
|
- const path = this.$route.path
|
|
|
- const nextPath = '/video/gz5RYkw1zn'
|
|
|
- if (path !== nextPath) {
|
|
|
- this.$router.push(nextPath)
|
|
|
- } else {
|
|
|
- console.log('视频播放完成')
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- player.on('volumechange', () => {
|
|
|
- console.log('声音改变')
|
|
|
- })
|
|
|
- },
|
|
|
initFlvPlayer(videoId, coverUrl, videoUrl) {
|
|
|
- const dp = new DPlayer({
|
|
|
+ new DPlayer({
|
|
|
container: document.getElementById('dplayer'),
|
|
|
live: true,
|
|
|
danmaku: false,
|