Caststatuschanged catch error: "Cannot read property 'newStatus' of undefined"
See original GitHub issueI catch error, when set addEventListener
.
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.
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:
- Created 4 years ago
- Comments:11 (6 by maintainers)
Top 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 >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 FreeTop 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
Top GitHub Comments
@ivansteff Is this the same application as you reference above or a different one? 😃
Using the code you posted above:
@ismena Finally, I get it! Many thanks to your team for such a detailed explanation!