这个问题很头疼.. 我花了几个小时到处寻找解决方案。 我的目标是通过调用触发视频和单独音频的函数(无论是通过 onclick 还是 mousedown 监听器)来在 iOS 上启动/播放视频和单独的音频。 例如:
html:
<html>
<video id="videoElement" src="video/video.mp4"></video>
<audio id="AudioElement">
<source id="sfile" src="file.mp3">
</audio>
<div id="btDiv"> play</div>
</html>
js:
var mybt = document.getElementById('btDiv');
var myVideo = document.getElementById("videoElement");
var myAudio = document.getElementById('AudioElement')
mybt.addEventListener('touchstart', function(){ myVideo.play();myAudio.play(); }, false);
这可能吗?
此外...是否可以使用不同的按钮而不是默认的 UI 播放器按钮在 iOS 上播放视频?
谢谢:)
最佳答案
尝试此 HTML 5 代码
NSString *embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
<script>\
function load(){document.getElementById(\"yt\").play();}\
</script>\
</head><body onload=\"load()\"style=\"margin:0\">\
<video id=\"yt\" src=\"%@\" \
width=\"%0.0f\" height=\"%0.0f\" poster=\"%@\" autoplay controls></video>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML,@"http://www.youtube.com/v/HGd9qAfpZio&hl=en_US&fs=1&", self.webView.frame.size.width, self.webView.frame.size.height,@""];
[self.webView loadHTMLString:html baseURL:nil];
关于javascript - 在 iOS 上同时播放 Html5 视频和音频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21230713/