VideoJS Error: The element or ID supplied is not valid

VideoJS Error: The element or ID supplied is not valid

我是 videojs 的新手 lightning.js。我尝试使用 document.querySelector 但仍然出现相同的错误。我想可能是因为浏览器的原因,所以我在 chrome、firefox、edge.

中尝试了

TypeError: The element or ID supplied is not valid. (videojs) at videojs (video.es.js:27887) at Function._template (App.js:19) at Function.getTemplateFunc (lightning.js:9068) at new Component (lightning.js:9016) at new App (App.js:4) at Stage.element (lightning.js:13634) at Stage.c (lightning.js:13642) at index.js:117 ,i am getting error in this line -> var player = videojs('myvideo')

import { Lightning, Utils } from '@lightningjs/sdk'
import videojs from 'video.js'

export default class App extends Lightning.Component {
  static getFonts() {
    return [{ family: 'Regular', url: Utils.asset('fonts/Roboto-Regular.ttf') }]
  }

  static _template() {
    var video = document.createElement('video')
    var source = document.createElement('source')
    console.log(video);
    
    video.setAttribute("id","myvideo");
    video.setAttribute("class","video-player");
    source.setAttribute("type", 'video/mp4');
    source.setAttribute("src", "https://github.com/googleboy0/Programming/raw/main/Dilwale%20Dulhania%20Le%20Jayenge%20-%20Trailer%20(with%20English%20Subtitles).mp4")
    video.appendChild(source);
    var player = videojs('myvideo')
    player.play()

  }
}

您正在创建一个元素,但从未将其添加到文档中。因此,图书馆找不到它。 (你给它一个 ID,而不是一个实际的元素。)请参阅 createElement 的文档了解如何完成。