H5+ plus.video.VideoPlayer播放视频,兼容IOS和android
H5页面,只要添加所以要的id="video"元素就行
<div id="video" style="width:98%;height:250px;background-color:#ffffff;margin:auto"></div>
JS代码
var playing = false;
// H5 plus事件处理
// 监听plusready事件
document.addEventListener( "plusready", function(){
// 扩展API加载完毕,现在可以正常调用扩展API
plusReady();
}, false );
function plusReady(){
// 创建视频播放控件
video = new plus.video.VideoPlayer('video',{
src:getWebUrl("视频地址"),
autoplay:true
});
video.addEventListener('play', function(){
updatePlaying(true);
}, false);
video.addEventListener('pause', function(){
updatePlaying(false);
}, false);
}
// 更新为播放状态
function updatePlaying(play) {
playing = play;
// document.getElementById('pp').innerText = playing?'暂停':'播放';
}
// 播放/暂停
function ppVideo() {
playing?video.pause():video.play();
}
// 全屏
function fullscreenVideo() {
video.requestFullScreen(-90);
}
注意:全屏在IOS端需要在AppDelegate.m后面加上这段话是在整个类后面END之后,否则全屏后无法恢复
@implementation UINavigationController(Orient)
-(BOOL)shouldAutorotate{
return ![PDRCore Instance].lockScreen;
return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
return [self.topViewController supportedInterfaceOrientations];
}
@end