question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to add mux.js for shaka in Reactjs app

See original GitHub issue

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 '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:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
GlitterCakescommented, May 10, 2019

@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.

2reactions
joeyparrishcommented, May 9, 2019

Add a <script> tag to your HTML that loads mux.js. As long as it is loaded before you instantiate an instance of shaka.Player, you will get the benefit of mux.js in that instance.

Does this answer your question?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found