【发布时间】:2019-09-21 21:14:08
【问题描述】:
我无法在 iOS 和 Android 设备上播放我的视频。使用 Safari 远程调试时,出现以下问题:
Unhandled Promise Rejection: AbortError: The operation was aborted.
我的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>
我的 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()
})
总结:无论我采用相对路径还是绝对路径,两者都不仅仅适用于 iOS 和 Android 设备上的移动浏览器(Chrome、Safari)。
【问题讨论】:
标签: javascript android html html5-video mobile-safari