iPhone 无法在 a-frame 框架下播放视频纹理
Can't play video texture under a-frame framework on iPhone
我们使用这个框架 https://aframe.io/ 来开发虚拟现实网站。
我们的场景包含带有视频纹理的球体。它在台式机和某些 android 设备上运行良好,但我们无法在 iPhone 上开始视频播放 6. Mobile Safari 仅显示视频的第一帧。有人知道如何解决这个问题吗?
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Player</title>
<meta name="description" content="Player">
<script src="https://aframe.io/releases/latest/aframe.min.js"></script>
</head>
<body>
<a-scene>
<a-camera position="0 0 0" cursor="fuse: true; maxDistance: 30; timeout: 3000" wasd-controls-enabled="true"></a-camera>
<!-- Creating 360 deg screen -->
<a-videosphere src="/images/super_cute_cat.mp4" autoplay="true" loop="true" rotation="0 0 0"></a-videosphere>
</a-scene>
</body>
</html>
此问题在 https://github.com/aframevr/aframe/issues/316#issuecomment-183006679
中有详细说明
iOS 对播放内联视频有限制。我们需要在视频元素上定义 webkit-playsinline
。我们需要将应用程序固定到主屏幕才能正常工作。
我们目前正在为 iOS 开发模式,以在 iOS 重新访问此限制之前帮助改善此体验。
编辑:或者,您不必将应用程序固定到主屏幕。但视频纹理将在 iOS 视频播放器中启动。用户可以关闭此视频,然后向上滚动以隐藏浏览器 chrome。但这种体验可以说比将应用程序固定到主屏幕更糟糕,尤其是当您有多个视频纹理时。
目前我在 Android 上使用 Firefox,确保选中设置->高级->自动播放。
否则 iOS 如果固定到主屏幕,它对我有用。
我相信很多网络供应商都会在这方面努力让 VR 与视频一起工作。
更新:(旧答案不再适用)
使用iphone-inline-video JS模块。您可以内联播放 360 度全景视频(无需固定到主屏幕)。
我已尝试更新该模块的文档,以便它演示如何将 Aframe 与 iOS here.
一起使用
这里是完整性的来源(您的视频必须是本地的,见下文):
<!DOCTYPE html>
<!-- Source: https://github.com/aframevr/aframe/blob/v0.3.2/examples/boilerplate/360-video/index.html -->
<html>
<head>
<meta charset="utf-8">
<title>Aframe 360 Video with iOS Support</title>
<meta name="description" content="360 Video — A-Frame">
<style>
#playoverlay { position: relative; }
#play-button {
position: absolute;
bottom: 30px;
left: 30px;
}
/* Hide native iOS controls */
.IIV::-webkit-media-controls-play-button,
.IIV::-webkit-media-controls-start-playback-button {
opacity: 0;
pointer-events: none;
width: 5px;
}
</style>
</head>
<body>
<a-scene>
<a-assets>
<video id="video" src="sample.mp4" autoplay loop crossorigin playsinline></video>
</a-assets>
<a-videosphere src="#video" rotation="0 180 0"></a-videosphere>
</a-scene>
<div id="playoverlay">
<button id="play-button">Play / Pause</button>
</div>
<script src="https://aframe.io/aframe/dist/aframe.js"></script>
<script src="../dist/iphone-inline-video.browser.js"></script>
<script>
(function() {
var video = document.querySelector('#video');
window.makeVideoPlayableInline(video, /* mute necessary for autoplay*/ false);
var playButton = document.querySelector('#play-button');
playButton.addEventListener('click', function(e) {
if (video.paused) {
video.play();
} else {
video.pause();
}
});
})();
</script>
</body>
</html>
iOS/Mobile Safari 注意事项:
在 iOS
上,视频源必须是本地的(iOS/Safari 似乎是唯一存在视频 src
CORS 问题的主要浏览器,并且(取决于 software/hardware), 视频可能需要在一定的分辨率下。例如,要支持 iPhone 5,我发现我无法播放任何大于 1920x1080 的视频,YMMV...
其他注意事项:
- 通过 360 度全景视频的控件控制音频是不行的。 iOS Safari 上的音量是只读的(参见here)。
- iOS 上的 Safari 不允许在 iFrames 中进行 gyroscopic/sensor 检测 - 因此,如果您想要 [= =54=] 工作(参见 here),因此您的 iOS 用户将无法获得 A-Frame 免费提供的任何出色的移动控制。
- iOS/Safari 不支持全屏 (
iOS Safari doesn't have a fullscreen API, but we do on Chrome on Android, Firefox, and IE 11+
),参考 here。 "Safari supports full screen in videos" 仅在回退到其本机播放器时有效的论点(在这种情况下,A-Frame/Three.js 环绕 canvas 球体的 360 度视频纹理不起作用,因为你有看起来很糟糕的平面 360 度视频)。
让视频(在我的例子中是 360 度视频)在 iOS 上播放一直是一个相当大的挑战,但是有很多让步是可能的。
我们使用这个框架 https://aframe.io/ 来开发虚拟现实网站。 我们的场景包含带有视频纹理的球体。它在台式机和某些 android 设备上运行良好,但我们无法在 iPhone 上开始视频播放 6. Mobile Safari 仅显示视频的第一帧。有人知道如何解决这个问题吗?
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Player</title>
<meta name="description" content="Player">
<script src="https://aframe.io/releases/latest/aframe.min.js"></script>
</head>
<body>
<a-scene>
<a-camera position="0 0 0" cursor="fuse: true; maxDistance: 30; timeout: 3000" wasd-controls-enabled="true"></a-camera>
<!-- Creating 360 deg screen -->
<a-videosphere src="/images/super_cute_cat.mp4" autoplay="true" loop="true" rotation="0 0 0"></a-videosphere>
</a-scene>
</body>
</html>
此问题在 https://github.com/aframevr/aframe/issues/316#issuecomment-183006679
中有详细说明iOS 对播放内联视频有限制。我们需要在视频元素上定义 webkit-playsinline
。我们需要将应用程序固定到主屏幕才能正常工作。
我们目前正在为 iOS 开发模式,以在 iOS 重新访问此限制之前帮助改善此体验。
编辑:或者,您不必将应用程序固定到主屏幕。但视频纹理将在 iOS 视频播放器中启动。用户可以关闭此视频,然后向上滚动以隐藏浏览器 chrome。但这种体验可以说比将应用程序固定到主屏幕更糟糕,尤其是当您有多个视频纹理时。
目前我在 Android 上使用 Firefox,确保选中设置->高级->自动播放。
否则 iOS 如果固定到主屏幕,它对我有用。
我相信很多网络供应商都会在这方面努力让 VR 与视频一起工作。
更新:(旧答案不再适用)
使用iphone-inline-video JS模块。您可以内联播放 360 度全景视频(无需固定到主屏幕)。
我已尝试更新该模块的文档,以便它演示如何将 Aframe 与 iOS here.
一起使用这里是完整性的来源(您的视频必须是本地的,见下文):
<!DOCTYPE html>
<!-- Source: https://github.com/aframevr/aframe/blob/v0.3.2/examples/boilerplate/360-video/index.html -->
<html>
<head>
<meta charset="utf-8">
<title>Aframe 360 Video with iOS Support</title>
<meta name="description" content="360 Video — A-Frame">
<style>
#playoverlay { position: relative; }
#play-button {
position: absolute;
bottom: 30px;
left: 30px;
}
/* Hide native iOS controls */
.IIV::-webkit-media-controls-play-button,
.IIV::-webkit-media-controls-start-playback-button {
opacity: 0;
pointer-events: none;
width: 5px;
}
</style>
</head>
<body>
<a-scene>
<a-assets>
<video id="video" src="sample.mp4" autoplay loop crossorigin playsinline></video>
</a-assets>
<a-videosphere src="#video" rotation="0 180 0"></a-videosphere>
</a-scene>
<div id="playoverlay">
<button id="play-button">Play / Pause</button>
</div>
<script src="https://aframe.io/aframe/dist/aframe.js"></script>
<script src="../dist/iphone-inline-video.browser.js"></script>
<script>
(function() {
var video = document.querySelector('#video');
window.makeVideoPlayableInline(video, /* mute necessary for autoplay*/ false);
var playButton = document.querySelector('#play-button');
playButton.addEventListener('click', function(e) {
if (video.paused) {
video.play();
} else {
video.pause();
}
});
})();
</script>
</body>
</html>
iOS/Mobile Safari 注意事项:
在 iOS
上,视频源必须是本地的(iOS/Safari 似乎是唯一存在视频 src
CORS 问题的主要浏览器,并且(取决于 software/hardware), 视频可能需要在一定的分辨率下。例如,要支持 iPhone 5,我发现我无法播放任何大于 1920x1080 的视频,YMMV...
其他注意事项:
- 通过 360 度全景视频的控件控制音频是不行的。 iOS Safari 上的音量是只读的(参见here)。
- iOS 上的 Safari 不允许在 iFrames 中进行 gyroscopic/sensor 检测 - 因此,如果您想要 [= =54=] 工作(参见 here),因此您的 iOS 用户将无法获得 A-Frame 免费提供的任何出色的移动控制。
- iOS/Safari 不支持全屏 (
iOS Safari doesn't have a fullscreen API, but we do on Chrome on Android, Firefox, and IE 11+
),参考 here。 "Safari supports full screen in videos" 仅在回退到其本机播放器时有效的论点(在这种情况下,A-Frame/Three.js 环绕 canvas 球体的 360 度视频纹理不起作用,因为你有看起来很糟糕的平面 360 度视频)。
让视频(在我的例子中是 360 度视频)在 iOS 上播放一直是一个相当大的挑战,但是有很多让步是可能的。