Open munirot opened 4 years ago
I have the same problem and i using the Nuxt: Make the request in function 'asyncdata' , but it failed because Nuxt is SSR error info is:
😢😢😢
<template>
<v-app>
<div class="video-player-box"
@play="onPlayerPlay($event)"
@pause="onPlayerPause($event)"
@ready="playerReadied"
@statechanged="playerStateChanged($event)"
v-video-player:myVideoPlayer="this.playerOptions">
</div>
</v-app>
</template>
<script>
import Vue from 'vue'
import 'video.js/dist/video-js.css'
import axios from "@/.nuxt/axios";
if (process.browser) {
window.videojs = require('video.js')
require('video.js/dist/lang/zh-CN')
const Vplayer = require('vue-video-player/dist/ssr')
Vue.use(Vplayer)
const hls = require('videojs-contrib-hls')
Vue.use(hls)
}
export default {
data() {
return {
playerOptions: {
hls: true, //启用hls?
// fluid: true, //设置播放器为流体 宽度为外层盒子大小 ps:想设置width:100%找不到方法?这个就对了
// muted: false,
language: 'zh-CN',
// playbackRates: [0.7, 1.0, 1.5, 2.0],
sources: [{
type: 'application/x-mpegURL',
src: this.info.url
}],
poster: '/static/v.png',
}
}
},
beforeCreate() {
// this.$axios.get(`/video/1`).then(res=>{
// this.playerOptions.sources[0].src = res.data.url
//
// })
},
methods: {
watchVideo() {
this.playerOptions.sources[0].src = "https://mei.huazuida.com/20200104/20705_f63cddc7/index.m3u8"
},
// listen event
onPlayerPlay(player) {
// console.log('player play!', player)
},
onPlayerPause(player) {
// console.log('player pause!', player)
},
// ...player event
// or listen state event
playerStateChanged(playerCurrentState) {
// console.log('player current update state', playerCurrentState)
},
// player is ready
playerReadied(player) {
console.log('the player is readied', player)
// you can use it to do something...
// player.[methods]
}
},
// async asyncData({params ,$axios}) {
// // console.log(await axios.get('https://api.myjson.com/bins/1dkbio'))
// let {data} = await $axios.get('/video/' + params.id)
// return {info: data}
// }
}
</script>
For Nuxt.js, i can't make the SSR working. So, I'm using the client only plugin. This is my plugin file
import Vue from 'vue'
import videojs from 'video.js'
window.videojs = videojs
// No need to require videojs-contrib-hls as videojs v7 already support hls streaming
const VueVideoPlayer = require('vue-video-player/dist/vue-video-player')
Vue.use(VueVideoPlayer)
Set the plugins in nuxt.config.js
...
plugins: [
{
src: '~/plugins/nuxt-video-player-plugin.js',
mode: 'client'
},
...
Vue.js version and component version
"nuxt": "^2.6.3"
What is Expected?
Set sources src to dynamic src fetch from API
What is actually happening?
I want to set dynamic src to the player where I got the link from my API where I store in the data state (media.url). With this library, I've tried to set the source url I stored in media.url to the player source when created
I got the blank canvas, and when I inspect element, I see the html5 video-tag does not include src in it. How to do it?