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.

Caststatuschanged catch error: "Cannot read property 'newStatus' of undefined"

See original GitHub issue

I catch error, when set addEventListener.

image

Init, and call like this question.

shaka.pl.js

export default class ShPlayer {

	async changeUrl(newUrl) {
		const video = document.getElementById('video');
		const videoContainer = document.getElementById('videoContainer');
		const player = new shaka.Player(video);

		const ui = new shaka.ui.Overlay(player, videoContainer, video);
		const controls = ui.getControls();

		controls.addEventListener('caststatuschanged', this.onCastStatusChanged());

		try {
			await player.load(newUrl);
		} catch (error) {
			console.error(error);
		}
	}
	
	onCastStatusChanged(event) {
		const newCastStatus = event['newStatus'];
		// Handle cast status change
		console.log('The new cast status is: ' + newCastStatus);
	}
	
	onPlayerErrorEvent(errorEvent) {
		// Extract the shaka.util.Error object from the event.
		this.onPlayerError(event.detail);
	}

	onPlayerError(error) {
		// Handle player error
		 console.error('Error code', error.code, 'object', error);
	}

	onUIErrorEvent(errorEvent) {
		// Extract the shaka.util.Error object from the event.
		this.onPlayerError(event.detail);
	}

	initFailed() {
		// Handle the failure to load
		console.error('Unable to load the UI library!');
	}
}

Player.vue

<template>
    <div>
        <div  ref="main" data-shaka-player-container data-shaka-player-cast-receiver-id="7B25EC44">
            <video data-shaka-player ref="video" id="video"
                autoplay controls></video>
        </div>
    </div>
</template>

<script>
    import ShakaPlayer from '../shaka.pl.js';
    export default {
        name: "Player",
        data() {},
        mounted() {
            var a = new ShakaPlayer ();
            a.changeUrl(someUrl);

        },
    };
</script>

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width,initial-scale=1.0"/>
    <title>
        Player
    </title>
    <link href="https://fonts.googleapis.com/css?family=Rubik:300,400,500" rel="stylesheet"/>
    <script defer src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js"></script>
    <script src="./shaka-player.ui.debug.js"></script>
    <link rel="stylesheet" href="./controls.css"/>
</head>
<body>
<div id="app"></div>
<script src="/mux.js"></script>
</body>
</html>

If remove line controls.addEventListener('caststatuschanged', this.onCastStatusChanged()); video play. Controls appear, but there are no cast buttons among them. image

And incorrect time. (when i change url, i set url to live stream) I did everything according to the example

If i set my url to shaka demo page . Always ok, i can select tv to cast, cast was working.

Why doesn’t the cast button appear? What could I do wrong?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ismenacommented, Nov 14, 2019

@ivansteff Is this the same application as you reference above or a different one? 😃

Using the code you posted above:

export default class ShPlayer {
	
	constructor() {
		this.video = document.getElementById('video');
		this.videoContainer = document.getElementById('videoContainer');
		this.player = new shaka.Player(this.video);
	        this.ui = new shaka.ui.Overlay(this.player, this.videoContainer, this.video);
            this.controls = this.ui.getControls();
            // TRY THIS!
            this.ui.configure('castReceiverAppId', '7B25EC44');
		this.controls.addEventListener('caststatuschanged', (e) => this.onCastStatusChanged(e));
	}
	async changeUrl(newUrl) {
		try {
			await this.player.load(newUrl);
		} catch (error) {
			console.error(error);
		}
	}
	onCastStatusChanged(event) {
		const newCastStatus = event['newStatus'];
		// Handle cast status change
		console.log('The new cast status is: ' + newCastStatus);
	}

}
0reactions
ivansteffcommented, Nov 15, 2019

@ismena Finally, I get it! Many thanks to your team for such a detailed explanation!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Caststatuschanged catch error: "Cannot read property ...
I catch error, when set addEventListener. ... Caststatuschanged catch error: "Cannot read property 'newStatus' of undefined" #2235.
Read more >
How to Catch "TypeError: Cannot read properties of undefined ...
Now when i try to access a property which may or may not exist, in case, it does not exist then how to...
Read more >
JSDoc: Tutorial: UI Library - Shaka Player Demo
Setting up the UI library. Setting up a project with the UI library is even easier than setting one up without. Set up...
Read more >
How to Avoid Getting 'Cannot read property of undefined' in ...
Learn how you can avoid getting the famous 'Cannot read property of undefined' error in JavaScript with the logical OR operator.
Read more >
How to Fix: cannot read property of undefined JavaScript
The error “Uncaught TypeError: Cannot read properties of undefined” occurs when we are trying to access a property from a null or undefined...
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