在做小程序時,遇到播放視頻,希望直接點擊視頻便全屏播放,uniapp 文檔上也有介紹 https://uniapp.dcloud.io/api/media/video-context?id=createvideocontext
重要的事情說三遍 this this this,記得createVideoContext第一個參數為video的ID,第二個參數組件實例this
this.videoContext = uni.createVideoContext(id,this); this.videoContext.requestFullScreen();
<video id="myVideo" :src="videoUrl" @fullscreenchange="fullscreenchange"></video>
退出全屏時,停止播放
fullscreenchange (e){ if(!e.detail.fullScreen){ this.videoContext.stop() } }