We're migrating to VideoJS in ReactJS project, everything seems to work fine except for google IMA plugin.
Are there any resources on how to use google-ima plugin in React? https://www.npmjs.com/package/videojs-ima-player
I'm getting 'Uncaught Error: plugin "ima" does not exist' error here
import React from "react";
import videojs from 'video.js'
import 'videojs-ima';
class VideoJS extends React.Component {
constructor(props) {
super(props)
console.log(this.props)
}
generetePlayerOptions = () => {
return (
{
autoplay: true,
controls: true,
language: 'lt',
poster: this.props.playlist[0].image,
aspectRatio: '16:9',
sources: [{
src: this.props.playlist[0].file,
type: 'video/mp4'
}],
plugins: {
ima: {
adTagUrl: 'http://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/ad_rule_samples&ciu_szs=300x250&ad_rule=1&impl=s&gdfp_req=1&env=vp&output=xml_vmap1&unviewed_position_start=1&cust_params=sample_ar%3Dpremidpostpod%26deployment%3Dgmf-js&cmsid=496&vid=short_onecue&correlator='
}
}
}
)
}
componentDidMount() {
// instantiate Video.js
this.player = videojs(this.videoNode, this.generetePlayerOptions(), function onPlayerReady() {
console.log('onPlayerReady', this)
})
}
Looks like it won't work if you import it. I don't like too much what i did but it works.
In the render function you just have to define the id for the video tag (same as the one on ComponentDidMount)
The ad won't start if there is no source for the player.