视频在React JS中不会自动播放。

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

Video is not playing automatically in React JS

问题

嗨,我想要在没有控件的情况下自动播放视频,因为我将其用作网站横幅背景。请指出我做错了什么。我正在使用Chrome浏览器。

``` HTML
<video
  autoPlay
  // playsinline
  autoplay
  muted
  loop
  className="stakingNft"
>
<source src="\assets\video\landing.mp4" type="video/mp4" />
</video>

<video
  autoPlay
  playsinline
  autoplay
  muted
  loop
  className="stakingNft"
>
<source src="\assets\video\landing.mp4" type="video/mp4" />
</video>

<details>
<summary>英文:</summary>

Hy, I want to play videos automatically without controls. because I&#39;m using it as a website banner background. Please point out what I have done wrong. I&#39;m using chrome browser.

<video
autoPlay
// playsinline
autoplay
muted
loop
className="stakingNft"
>
<source src="\assets\video\landing.mp4" type="video/mp4" />
</video>


<video
autoPlay
playsinline
autoplay
muted
loop
className="stakingNft"
>
<source src="\assets\video\landing.mp4" type="video/mp4" />
</video>


</details>


# 答案1
**得分**: 0

看起来视频路径有问题。
你使用了反斜杠而不是正斜杠。

参考链接:https://stackblitz.com/edit/react-xbfng5?file=src%2FApp.js

<details>
<summary>英文:</summary>

Looks like there&#39;s issue in path of video.
You used backward slash instead of forward slash.


Here is the reference: https://stackblitz.com/edit/react-xbfng5?file=src%2FApp.js

----------


</details>



# 答案2
**得分**: 0

以下是翻译好的内容:

这里是[CodeSandbox][1]。

autoPlay可能被定义了两次,而且用小写字母,我认为这可能是原因。

[1]: https://codesandbox.io/s/peaceful-archimedes-imdure?file=/src/App.js

<details>
<summary>英文:</summary>

Here is the [codesandbox][1]

autoPlay might be defined twice and in small case that&#39;s the reason I think.

  [1]: https://codesandbox.io/s/peaceful-archimedes-imdure?file=/src/App.js

</details>



huangapple
  • 本文由 发表于 2023年1月6日 13:25:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75027227.html
匿名

发表评论

匿名网友

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

确定