我使用sproutvideo
存储视频,我尝试使用jQuery UI设置控制栏,但播放按钮不适用于iPhone和iPad等Apple设备。
这是有效的link。
那是我的代码。
var videoPlayer;
$(document).ready(function(){
$('.progress').slider({
value: 0,
orientation: "horizontal",
range: "min",
animate: true,
slide: function(event, ui) {
videoPlayer.seek(ui.value);
}
});
var _duration = 0, _playing = false, _volume = 1, _fullscreen = false;
var videoPlayer = new SV.Player({videoId: 'e898d2b5111be3c860'});
videoPlayer.bind('ready', function(event){
_duration = event.data.duration;
$(".progress").slider("option", "max", _duration);
});
videoPlayer.bind('progress', function(event){
$('.progress').slider("option", "value", (event.data.time));
});
videoPlayer.bind('pause', function(event){
_playing = false;
$('.play-pause i').removeClass('icon-pause').addClass('icon-play');
});
videoPlayer.bind('play', function(event){
_playing = true;
$('.play-pause i').removeClass('icon-play').addClass('icon-pause');
});
videoPlayer.bind('volume', function(event){
_volume = event.data;
if (_volume == 1) {
$('.volume i').removeClass('icon-volume-off').addClass('icon-volume-up');
} else if (_volume == 0) {
$('.volume i').removeClass('icon-volume-up').addClass('icon-volume-off');
}
});
$('.play-pause a').click(function(){
if (!_playing) {
videoPlayer.play();
} else {
videoPlayer.pause();
}
});
$('.volume a').click(function(){
if (_volume == 0) {
_volume = 1;
} else {
_volume = 0;
}
videoPlayer.setVolume(_volume);
});
$('.fullscreen a').click(function(){
var elem = $('.player')[0];
if (!_fullscreen) {
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) {
elem.webkitRequestFullscreen();
}
_fullscreen = true;
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
}
_fullscreen = false;
}
});
});
html {
background: url(http://4walled.cc/src/7e/7e857f5f0db89a65aabcc6ed527a2743.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.player {
width: 640px;
height: 403px;
position: relative;
margin: 50px auto;
border: 1px solid #CCC;
box-shadow: 1px 1px 15px #CCC;
}
.video {
position: absolute;
left:0;
right:0;
top: 0;
bottom:43px;
}
.control {
float: left;
padding: 0 10px;
}
.toolbar {
position: absolute;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(255,255,255,0.8);
padding: 13px 0 13px;
}
.control a {
text-decoration: none;
color: #000000;
}
.progress-container {
position: absolute;
left: 43px;
right: 79px;
width: auto;
}
.volume, .fullscreen {
float: right;
}
.player:-webkit-full-screen {
width: 100%;
height: 100%;
}
<script type="text/javascript" src="http://c.sproutvideo.com/player_api.js"></script>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.0.2/css/font-awesome.min.css">
<div class="player">
<div class="video">
<iframe class='sproutvideo-player' type='text/html' src='https://videos.sproutvideo.com/embed/e898d2b5111be3c860/546cd1548010aaeb?type=sd&noBigPlay=true&showcontrols=false' width='100%' height='100%' frameborder='0'></iframe>
</div>
<div class="toolbar">
<div class="control play-pause"><a href="#"><i class="icon-play"></i></a></div>
<div class="progress-container">
<div class="progress"></div>
</div>
<div class="control fullscreen"><a href="#"><i class="icon-fullscreen"></i></a></div>
<div class="control volume"><a href="#"><i class="icon-volume-up"></i></a></div>
</div>
</div>
答案 0 :(得分:0)
移动版Safari不允许调用play()
上的<video>
方法,除非它由MouseEvent
触发。由于SproutVideo播放器API使用Window.postMessage()
与播放器iframe进行通信,MouseEvent
将丢失,Safari将不允许调用play()
函数。对于YouTube javascript API,Vimeo javascript API以及与使用iframe的基于iframe的视频播放器进行通信的任何API,这也是一个问题。
不幸的是,目前还没有解决方法。一个好的临时解决方案是有条件地隐藏iOS设备上的自定义播放器控件,而是使用原生视频播放器。