由于src属性或分配的媒体提供程序引发的错误。

huangapple go评论77阅读模式
英文:

Error by the src attribute or assigned media provider

问题

我正尝试从从Google Firebase API获取的链接导入视频到一个类似TIKTOK的应用程序。但是,当我按播放按钮时,出现以下错误消息:

错误
由src属性或分配的媒体提供程序对象指示的媒体资源不适合。

下面是我正在使用的React代码,其中包含处理视频开始的函数。该视频是从Firebase存储的URL获取的。

import React, { useRef, useState } from "react";
import "./video.css";

function Video() {
  const videoRef = useRef(null);
  const [play, setPlay] = useState(false);

  function handleStart() {
    if (play) {
      videoRef.current.pause();
      setPlay(true);
    } else {
      videoRef.current.play();
      setPlay(true);
    }
  }

  return (
    <div className="video">
      <video
        className="video__player"
        ref={videoRef}
        onClick={handleStart}
        loop
        src="https://firebasestorage.googleapis.com/v0/b/jornada-dev.appspot.com/o/brecker2.mp4?alt=media&token=b5399418-9276-4e53-a706-1e00290c2c74"
      >
        
      </video>
    </div>
  );
}

export default Video;
英文:

I am attempting to import a video to a TIKTOK clone application from a link sourced from a Google Firebase API. However, the following error message appears when I press play:

> ERROR
The media resource indicated by the src attribute or assigned media provider object was not suitable.

Below is the React code I am using with a function to handle the start of the video. The video is sourced from a URL on Firebase Storage.

import React, { useRef, useState } from &quot;react&quot;;
import &quot;./video.css&quot;;

function Video() {
  const videoRef = useRef(null);
  const [play, setPlay] = useState(false);

  function handleStart() {
    if (play) {
      videoRef.current.pause();
      setPlay(true);
    } else {
      videoRef.current.play();
      setPlay(true);
    }
  }

  return (
    &lt;div className=&quot;video&quot;&gt;
      &lt;video
        className=&quot;video__player&quot;
        ref={videoRef}
        onClick={handleStart}
        loop
        src=&quot;https://firebasestorage.googleapis.com/v0/b/jornada-dev.appspot.com/o/brecker2.mp4?alt=media&amp;token=b5399418-9276-4e53-a706-1e00290c2c74&quot;
      &gt;
        
      &lt;/video&gt;
    &lt;/div&gt;
  );
}

export default Video;

答案1

得分: 0

当请求响应为对象或错误,而不是实际的媒体数据时,可能会引发媒体类型不匹配的错误。您可以尝试使用JavaScript首先获取媒体数据块,检查是否没有错误,并且对象类型确实是 mp4,然后才将其设置为 src,从而确保传递给 src 的类型是百分之百确定的。

onError={event => console.log(event.target.error.message)}

由于src属性或分配的媒体提供程序引发的错误。

英文:

Hi 👋 I may assume whenever the request responds with an object or error, and not an actual media blob, it would throw that error that media type was not suited.

You could try fetch the blob with javascript first, check if there is no error, and the object type is indeed mp4 and only after that set it to the src, thus being 100% sure of what type you pass to src.

  onError={event =&gt; console.log(event.target.error.message)}

由于src属性或分配的媒体提供程序引发的错误。

huangapple
  • 本文由 发表于 2023年6月16日 06:48:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76485955.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定