How to add mux.js for shaka in Reactjs app
See original GitHub issueI’m using shaka player in ReactJs application. How can I load mux.js before loading shaka player?
import React from 'react'
import shaka from 'shaka-player'
export default class HexPlayer extends React.Component {
componentDidMount() {
shaka.polyfill.installAll();
if (shaka.Player.isBrowserSupported()) {
var video = document.getElementById('video');
var player = new shaka.Player(video);
window.playerShaka = player;
this.initPlayer();
} else {
console.error('Browser not supported!');
}
}
componentWillReceiveProps(nextProps){
if(nextProps.url !== this.props.url){
this.initPlayer(true,nextProps.url);
}
}
initPlayer(kill,url){
playerShaka.addEventListener('error', this.onErrorEvent);
if(kill){
playerShaka.unload();
console.log("The Url is:"+url)
playerShaka.load(url).then(function() {
console.log('The video has now been loaded!');
}).catch(err=>{
this.onError
console.log("err 1")
console.log(err)
}
);
}
else{
console.log("The Url is:"+this.props.url)
playerShaka.load(this.props.url).then(function() {
console.log('The video has now been loaded!');
}).catch(err=>{
this.onError
console.log("err 2")
console.log(err)
});
}
}
onErrorEvent = (event) =>{
this.props.errorHandler(event)
this.onError(event.detail);
}
onError(error) {
console.log("Error occured2")
console.error('Error code', error.code, 'object', error);
}
componentWillUnmount() {
playerShaka.unload(this.props.url).then(function() {
console.log('The video has now been stopped!');
}).catch(err=>{
})
}
render() {
return (
<div>
<video id="video"
width="100%"
height='500'
poster={this.props.poster}
controls={true}
autoPlay={true}>
</video>
</div>
);
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
How to add mux.js for shaka in Reactjs app #1927 - GitHub
I'm using shaka player in ReactJs application. How can I load mux.js before loading shaka player? import React from 'react' import shaka from...
Read more >Shaka Player + Mux.js on live streaming on React
I have been trying to implement live streaming on Shaka Player. Normal Hls.js is working fine, but I can't seem to implement it...
Read more >Monitor Shaka player - Mux Docs
Include the Mux JavaScript SDK on every page of your web app that includes video. ... import shaka from "shaka-player"; import initShakaPlayerMux from ......
Read more >Monitor React native video - Mux Docs
This guide walks through integration with react-native-video to collect video ... Include the Mux JavaScript SDK on every page of your web app...
Read more >Send and receive real-time video from a React application | Mux
1. Add the Spaces JS SDK to your dependencies · 2. Connect to a Space and send audio and video · 3. Receive...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@joeyparrish Your advice on attaching it to window has worked, i was trying to attach it as “mux” but i noticed you said “muxjs” and now I have it working. For anyone else that needs to enable mux when using react, the following works
I created a component for shaka-player, in the top of my class file I did
import muxjs from "mux.js";Then I assigned it within my components class constructor like this
window.muxjs = muxjs;Thank you for the advice I really appreciate it.
Add a
<script>tag to your HTML that loads mux.js. As long as it is loaded before you instantiate an instance ofshaka.Player, you will get the benefit of mux.js in that instance.Does this answer your question?