组件来展示视频,并设置好相应的属性和事件监听: <video src="video.mp4" @play="onVideoPlay" @pause="onVideoPause"></video>
isPictureInPicture: - data() {
- return {
- isPictureInPicture: false
- };
- },
- methods: {
- onVideoPlay() {
- // 当视频开始播放时,判断是否需要开启小窗模式
- if (this.isPictureInPicture) {
- uni.createVideoPlayer({
- videoId: 'video-player',
- sources: [{
- src: 'video.mp4'
- }],
- autoplay: true,
- showFullscreenBtn: false,
- showCenterPlayBtn: false,
- showPlayBtn: false,
- pictureInPictureMode: true
- });
- }
- },
- onVideoPause() {
- // 当视频暂停时,关闭小窗模式
- if (this.isPictureInPicture) {
- uni.exitPictureInPicture();
- }
- }
- }
在上述代码中,当视频开始播放时,判断isPictureInPicture是否为true,如果是,则调用uni.createVideoPlayer()方法创建一个视频播放器,并传入相应的参数来开启小窗模式。当视频暂停时,调用uni.exitPictureInPicture()方法来关闭小窗模式。