项目中有需要结合视频做一个游戏,直接用iOS的Safari调试或发布web-moble,遇到视频在Android设备正常,iOS设备下无法播放问题。
Demo组件代码,项目设置中做好VideoPlayer和Button的关联:
// ************************************************************************************
import { _decorator, Component, Node, Canvas, VideoPlayer, Button } from ‘cc’;
const { ccclass, property } = _decorator;
@ccclass('Play')
export class Play extends Component {
@property({type:VideoPlayer})
private player:VideoPlayer = null;
@property({type:Button})
private btnplay:Button = null;
start () {
console.log(this.node);
this.btnplay.node.on(Node.EventType.TOUCH_START, (event:Event) => {
// console.log(this.player.isPlaying);
// var player = document.getElementsByClassName('cocosVideo')[0];
// console.log(player);
// player.play();
if (this.player.isPlaying) {
this.player.pause();
} else {
this.player.play();
}
}, this);
}
}
// ************************************************************************************
注:注释的四行代码是偿试以DOM对象模型方式播放,该代码在Mac的Chrome浏览器正常,Mac的Safari及iOS的Safari无效。
环境:
CocosCreator3.3.1
iOS10 - iOS14
以下是我偿试的HTML源生Demo,在iOS浏览器下是支持播放的。
// ************************************************************************************
// ************************************************************************************
