The error message thrown by the vue-youtube-embed plugin states that it is unable to access the 'src' property

Currently, I am utilizing the vue-youtube-embed library to embed a YouTube player within a Vue.js component.

Initially, the player functions perfectly upon loading the component. However, it fails to play videos after the component is destroyed and then mounted again.

On my website, I incorporate a router-view. When I navigate to the player component for the first time, everything works fine. But if I return to the home page and revisit the player component, I encounter this error:

Cannot read property 'src' of null

Here is the complete stack trace:

www-widgetapi.js:121 Uncaught TypeError: Cannot read property 'src' of
null at W.g.C
(https://s.ytimg.com/yts/jsbin/www-widgetapi-vflQKB5wA/www-widgetapi.js:121:84)
at V
(https://s.ytimg.com/yts/jsbin/www-widgetapi-vflQKB5wA/www-widgetapi.js:113:99)
at W.(anonymous function).getCurrentTime.Mb.(anonymous function) [as
loadVideoById]
(https://s.ytimg.com/yts/jsbin/www-widgetapi-vflQKB5wA/www-widgetapi.js:130:11)
at VueComponent.play (eval at (http://localhost:8080/app.js:1037:1),
:136:31) at VueComponent.boundFn [as play] (eval at
(http://localhost:8080/app.js:729:1), :165:14) at Vue$3.eval (eval at
(http://localhost:8080/app.js:1037:1), :73:18) at Vue$3.Vue.$emit
(eval at (http://localhost:8080/app.js:729:1), :2207:16) at
VueComponent.playSong (eval at (http://localhost:8080/app.js:1058:1),
:123:73) at boundFn (eval at (http://localhost:8080/app.js:729:1),
:165:14) at Proxy.invoker (eval at
(http://localhost:8080/app.js:729:1), :1738:18)

The player appears to be functioning correctly, and I only encounter this issue when attempting to play a video using the loadVideoById method.

You can explore the error firsthand on my website. (Work in Progress)

To replicate the error:

  1. Create a new station
  2. In the text input below the player, search for a YouTube video, select it from the search results
  3. Click on the playlist to play the video
  4. Use the back button to return to the main page
  5. Navigate back to the station you created
  6. Attempt to play the video again

I omitted posting any code as the issue arises specifically when calling the loadVideoById method; during debugging, it appears that the player is loaded and ready (not null).

Answer №1

After some investigation, it appears that the issue stemmed from disconnecting the YouTube player from the DOM. This action triggered an error within the Player object, and despite my efforts to find a resolution, I ultimately decided to maintain its component constantly visible by utilizing

v-show

in place of

v-if

Answer №2

If you see something similar to this ...

html

<youtube @ready="ready" ....>

js

ready(event) {
  this.player = event.target;
  ....
}

This method was successful for me ...

created or when the videoId changes

this.player = null;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Identifying the precise image dimensions required by the browser

When using the picture tag with srcset, I can specify different image sources based on viewport widths. However, what I really need is to define image sources based on the actual width of the space the image occupies after the page has been rendered by th ...

Using the ternary operator to verify multiple strings

I am encountering an issue with a piece of code that involves checking if the value is null or turnedoff, then inserting a blank space into the variable on the left-hand side. However, I have noticed that the turnedoff value is not being replaced as expect ...

Dynamic variable declarations in JavaScript

Imagine having an object: function obj() { this.prop1; this.prop2; this.prop3; } and a collection of these objects objects = [new obj(),new obj(),new obj()]; The goal is to smoothly loop through each object using jQuery where the class name ma ...

Using V-for in Vue.js to iterate over data sources

I am attempting to display all elements of an array, but currently can only show the first line due to [0]. I want to show all items in the array. <div class="description" v-for="item in sitePartVoice[0].part_attributes"> <small><strong> ...

Chrome Back button problem arises following interaction with Iframe in Angular

I am currently working on an Angular application that involves a specific process: Users follow a flow and end up on one of the partial pages. From this partial page, I trigger a button to fetch an ID from a cross domain using a service call (no CORS ...

The priority of custom attributes in HTML

There seems to be some ambiguity regarding whether data- attributes should be considered primary or secondary syntax. Is there a defined standard for this in major frameworks like Angular? For example, if an attribute is specified as both my-attr and dat ...

Using Axios with Vue and Laravel 7 to set content in SymfonyComponentHttpFoundationResponse

Recently, I encountered an error while working with Laravel 7, Vue, and Axios. Despite my efforts, I couldn't pinpoint the cause of the issue. In my Laravel application, I utilize API routes for managing contacts without utilizing a controller, relyin ...

Is it possible to customize style based on a key in a v-for loop?

I'm currently working on a small application that changes styles based on keys in a v-for loop. I'm struggling to figure out how to update the style dynamically. My goal is to colorize one as blue, two as green, and three as red. <div id="ap ...

transmitting information from the state to actions in Vuex

I am trying to pass latitude and longitude coordinates from the state to an action in order to retrieve the city name based on the coordinates. However, I have noticed that using state.lat and state.lng directly in the axios.get URL does not work. What a ...

Code in VB.net that switches between two gridviews on a page automatically with the help of a timer

There are 2 gridviews on a single aspx page, and I want the second gridview to be displayed after the first gridview for 5 seconds and vice versa automatically, without any manual intervention. NOTE: This should happen on page load without clicking any bu ...

Guide to creating animations with javascript/react js

My attempt at altering the opacity of an element every 100 milliseconds following a click event has not been successful. The function change is triggered by a click, yet the code does not work as intended. Here's what I have so far: function change (i ...

Unable to proceed with the audio on React framework

Within the return statement of my React code, I have implemented an HTML audio object like so: <audio id="myAudio"> <source src="49.mp3" type="audio/mpeg"></source> </audio> This piece o ...

Guide to showing all selected users upon clicking in Vue

I am attempting to create a dynamic table using Vue.js, where users can select different workers to display their information on the screen. Being new to Vue.js, I am unsure of how to accomplish this. The code I currently have is provided below, and any as ...

Eliminate the JSON object within jqGrid's posted data

The web page I'm working on features Filters with two buttons that load data for jqGrid when clicked. Clicking 'Filter' generates a postData json object and sends it to the server, which is working perfectly. However, I'm facing an is ...

Tips on Using Firebase Database Rules to Validate a Node Property Value Against the User's Unique ID

I am currently utilizing the Firebase database and I am in the process of configuring rules to restrict write access to users whose uid matches the userId node of the object they are attempting to write, while still allowing the creation of new objects suc ...

Generate a progress indicator upon user clicking a hyperlink

I am looking to implement a loading bar that appears when the user clicks a link. Additionally, I need to upload data (via Ajax) into div#work if needed, followed by displaying the loading bar. Once the data is successfully uploaded, I want the script to s ...

TypeScript Implementation of ES6 Arrow Functions

Just diving into Typescript, I'm struggling to figure out the solution. I tried researching and looked into destructuring, but still unable to make it work. import React from "react"; import { StyleSheet, Text, View } from "react-native"; const st ...

A Beginner's Guide to Duplicating Bootstrap Containers in Jade

I am working with JSON data that is being transmitted from an Express and Mongoose Stack to be displayed on the user interface created in Jade. I am wondering which Jade Construct I should use to loop through a Bootstrap Container of col-md-4 using Jade s ...

VueJS displaying broken PNG images after deploying production build

After running the command npm run build, a dist folder is generated containing static assets such as images. The website is using history mode on vue router. Here's the HTML for the first image: https://i.sstatic.net/ZVArw.png Here's a snapsho ...

Showing and hiding elements inside a loop with AngularJS using ng-if and ng

While presenting a separate div based on a condition inside ng-repeat, I encountered an error message that reads "Syntax Error: Token '<' not a primary expression at column 32 of the expression [widget.Type == 'Bar'>". How can thi ...