简体   繁体   English

HTML5视频无法在iOS和Android上播放

[英]HTML5 Video doesn't play on iOS and Android

I can't play my video on iOS and Android Devices. 我无法在iOS和Android设备上播放我的视频。 When using Safari Remote Debugging, i get the following issue: 使用Safari远程调试时,我遇到以下问题:

Unhandled Promise Rejection: AbortError: The operation was aborted.

my html code 我的HTML代码

<video id="video" class="absolute right-0 bottom-0 min-w-full min-h-full w-auto" controls autoplay>
   <source src="/path/to/video.mp4" type="video/mp4">
   <!-- the absolute path doesn't work too -->
   <source src="https://example.com/path/to/video.mp4" type="video/mp4"> 
</video>

<!-- this code doesn't work too -->
<video id="video" src="/path/to/video.mp4" type="video/mp4" class="absolute right-0 bottom-0 min-w-full min-h-full w-auto" controls autoplay></video>

my JS Code 我的JS代码

let video = document.getElementbyId('video');
const videoPromise = document.querySelector('video').play();
let video_cta = document.getElementbyId('video_cta');

//this doesn't fix my problem
if (videoPromise !== undefined) {
    videoPromise.then(_ => {
      video.play();
    })
    .catch(error => {
       console.log(error);
    })
}

//this code doesn't work too:
function fetchVideoAndPlay() {
    fetch('https://example.com/file.mp4')
    .then(response => response.blob())
    .then(blob => {
      video.srcObject = blob;
      return video.play();
    })
    .then(_ => {
      // Video playback started ;)
    })
    .catch(e => {
      // Video playback failed ;(
    })
}

//start video after click the button
video_cta.addEventListener('click' function() {
    video.play()
})

Summary: Whether I take the relative or absolute path, both doesn't work only on mobile Browsers (Chrome, Safari) on iOS and Android Devices. 简介:无论我采用相对路径还是绝对路径,两者都不适用于iOS和Android设备上的移动浏览器(Chrome,Safari)。

Are you trying to autoplay the video or is the error happening, when you are pressing the play button? 当您按下播放按钮时,您是尝试自动播放视频还是发生错误?

If you are trying to autoplay videos, many browsers will no longer allow that if the video has sound turned on when you autoplay it. 如果您尝试自动播放视频,如果视频在自动播放时声音已打开,则许多浏览器将不再允许这样做。 It is possible to disable the audio and then autoplay the video. 可以禁用音频,然后自动播放视频。

<video id="video" controls autoplay>
   <source src="/path/to/video.mp4" type="video/mp4">
</video>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM