TylerLiu
TylerLiu
  • 发布:2024-10-25 18:36
  • 更新:2025-08-27 18:05
  • 阅读:296

【报Bug】 高版本IOS系统 在web-view中使用uni.postMessage , 导致视频暂停播放

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: windows11

HBuilderX类型: 正式

HBuilderX版本号: 4.29

手机系统: iOS

手机系统版本号: iOS 18

手机厂商: 苹果

手机机型: iphone15

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

示例代码:
uni.postMessage({  
        data: {  
            type: "wvLightControl",  
            value: lightEnabled  
        }  
    });

操作步骤:

调用uni.postMessage 方法, 视频就会卡死

预期结果:

调用uni.postMessage 方法, 视频正常播放

实际结果:

调用uni.postMessage 方法, 视频就会卡死

bug描述:

高版本IOS系统 在web-view中使用uni.postMessage , 导致视频暂停播放

2024-10-25 18:36 负责人:无 分享
已邀请:
DCloud_UNI_OttoJi

DCloud_UNI_OttoJi - 日常回复 uni-app/x 问题,如果艾特我没看到,请主动私信

你反馈 vue2 运行 ios18 真机有 webview 的问题,经过你测试本地可以稳定复现吗,你的 HBuilderX 版本是多少,提供一个单页面源码吧,相同的代码在其他系统没问题吗?

TylerLiu

TylerLiu (作者)

<!--https://github.com/feige05/g711.js   PCM to G711A -->  
<!DOCTYPE html>  
<html lang="en">  

<head>  
    <title> </title>  
    <meta charset="UTF-8">  
    <meta name="viewport" content="width=device-width, initial-scale=1.0">  
    <!-- <link rel="stylesheet" type="text/css" href="./css/index.css" /> -->  
    <!-- <script src="./js/jq.js" type="text/javascript" charset="utf-8"></script> -->  
    <!-- uni 的 SDK -->  
    <script type="text/javascript" src="js/web.mqtt.min.js"></script>  
    <script>  
        window.forceWebGL = true;  
        var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') || CSS.supports('top: constant(a)'))  
        document.write('<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' + (coverSupport ? ', viewport-fit=cover' : '') + '" />')  
    </script>  
    <!-- <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script> -->  
    <style>  
        html,  
        body {  
            background-color: #000000;  
            width: 100% !important;  
            height: 100% !important;  
        }  

        * {  
            margin: 0;  
            padding: 0;  
            border: 0;  
        }  

        #v1 {  
            position: absolute;  
            right: 0;  
            top: 20;  
            z-index: 100;  
            /* 镜像自己的画面 */  
            transform: scaleX(-1);  
        }  

        #v2,  
        #v3 {  
            position: absolute;  
            right: 0;  
            top: 0;  
            left: 0;  
            bottom: 0;  
            z-index: 1;  
            /* object-fit: cover; */  
        }  

        /* 隐藏video 播放按钮 */  
        .video::-webkit-media-controls-play-button {  
            display: none;  
        }  

        /* 隐藏video 进度条 */  
        .video::-webkit-media-controls-timeline {  
            display: none;  
        }  

        /* 隐藏video 观看的当前时间 */  
        .video::-webkit-media-controls-current-time-display {  
            display: none;  
        }  

        /* 隐藏video 剩余时间 */  
        .video::-webkit-media-controls-time-remaining-display {  
            display: none;  
        }  

        /* 隐藏video 全屏按钮 */  
        .video::-webkit-media-controls-fullscreen-button {  
            display: none;  
        }  

        /*  
    .video::-webkit-media-controls-enclosure {  
        display: none;  
    } */  

        .control-container {  
            position: fixed;  
            left: 0;  
            top: 0;  
            right: 0;  
            bottom: 0;  
            z-index: 99999;  
            opacity: 0;  
        }  

        .navback {  
            position: absolute;  
            left: 50px;  
            top: 30px;  
            background-color: rgba(0, 0, 0, .3);  
            border-radius: 100%;  
            width: 40px;  
            height: 40px;  
            display: flex;  
            justify-content: center;  
            align-items: center;  
        }  

        .navback img {  
            width: 25px;  
            height: 25px;  
        }  

        .joy-div1 {  
            width: 160px;  
            height: 160px;  
            background: rgba(0, 0, 0, 0.3);  
            border-radius: 100%;  
            position: absolute;  
            top: 50%;  
            left: 50%;  
            margin-left: -80px;  
            margin-top: -80PX;  
        }  

        .joy-div2 {  
            width: 80px;  
            height: 80px;  
            background: rgba(255, 255, 255, 0.7);  
            border-radius: 100%;  
            position: absolute;  
            top: 50%;  
            left: 50%;  
            margin-left: -40px;  
            margin-top: -40px;  
        }  

        .joy-div3 {  
            width: 160px;  
            height: 160px;  
            border-radius: 100%;  
            position: absolute;  
            top: 50%;  
            left: 50%;  
            margin-left: -80px;  
            margin-top: -80px;  
        }  

        .main-joy {  
            position: absolute;  
            width: 160px;  
            height: 160px;  
            left: 100px;  
            bottom: 70px;  
            z-index: -1;  
            opacity: 0;  
        }  

        .control-right {  
            position: absolute;  
            right: 30px;  
            top: 0;  
            bottom: 70px;  
            display: flex;  
            flex-flow: column;  
            align-items: center;  
            justify-content: flex-end;  
            box-sizing: border-box;  
            opacity: 0;  
            z-index: -1;  
            min-width: 50px;  

        }  

        .control-right-item {  
            display: flex;  
            flex-flow: column;  
            align-items: center;  
            margin-top: 15px;  
        }  

        .control-right-item-img {  
            width: 40px;  
            height: 40px;  
            background-color: rgba(0, 0, 0, .3);  
            border-radius: 100%;  
            display: flex;  
            justify-content: center;  
            align-items: center;  
        }  

        .control-right-item-img img {  
            width: 25px;  
            height: 25px;  
        }  

        .control-right-item-text {  
            color: #fff;  
            font-size: 10px;  
        }  

        .traffic-data {  
            position: absolute;  
            top: 2px;  
            right: 130px;  
            z-index: 99999;  
            border-radius: 15px;  
            padding: 2px 8px;  
            color: rgb(255, 255, 255, 0.8);  
            font-size: 12px;  
            background-color: rgba(0, 0, 0, 0.3);  
            display: flex;  
            align-items: center;  
        }  

        .traffic-img-bgpro {  
            width: 18px;  
            height: 18px;  
            margin-right: 2px;  
        }  

        .loading-in-progress {  
            position: absolute;  
            top: 50%;  
            left: 50%;  
            z-index: 99999;  
            margin-left: -25px;  
            margin-top: -25px;  
            color: #fff;  
        }  

        .movement-direction-icon {  
            /* display: none !important; */  
            position: absolute;  
            z-index: -1;  
            bottom: 0px;  
            left: calc(50% - 40px);  
            background-color: transparent;  
        }  

        .img-bgpro {  
            width: 50px;  
            height: 50px;  
        }  

        .img-bgpro-direction {  
            width: 100px;  
            height: 70px;  
        }  
    </style>  
</head>  

<body>  
<video onclick="mutedFun()" id="v2" src="http://cmkjfile.cqabox.com/aboxsvf/minio/2024/10/25/2C0640DB75F84D228E481E5F5DD1E4E4_A5692016ED704EA88400B4AFCF99F50C.mp4" class="video"  loop  playsinline autoplay></video>  

</body>  
<script type="text/javascript" src="js/uni.webview.1.5.5.js"></script>  
<script>  
    //静音  
    const mutedFun = () => {  
        uni.postMessage("asdasd");  
        console.log('播放网络地址')  
    }  

</script>  
</html>
TylerLiu

TylerLiu (作者)

下面是web-view的源代码, 需要把index.txt改为index.html。 web-view中执行uni.postMessage 视频就卡死不播放。

靐齉齾麤龖龗

靐齉齾麤龖龗 - 解决不了问题,那就解决提出问题的人

你在video上绑定的点击事件啊,你把video的controls放出来看看是不是单击暂停了呢?或者你把点击事件单独弄个按钮来操作看看会不会出现问题

Wiiill

Wiiill - No description

遇到一样的问题了,无论是 video 组件,第三方 video 组件,或者原生 html 写的网页,使用 web-view 加载这个网页。在网页中调用了 uni.postMessage 视频就会暂停

  • DCloud_UNI_yuhe

    你好,方便提供一下一个可以复现的项目吗?

    2025-08-27 19:05

  • Wiiill

    回复 DCloud_UNI_yuhe: 已私信回复

    2025-08-28 10:43

  • DCloud_UNI_yuhe

    回复 Wiiill: 出现此问题,暂时可以通过


          plus.webview.postMessageToUniNView({  
    type: "WEB_INVOKE_APPSERVICE",
    args: {
    data: {
    arg:{
    status:1
    },
    name:"postMessage",
    options: {
    timestamp:1756453427563
    }
    },
    webviewIds: ["1"]
    }
    }, "__uniapp__service");

    兼容一下

    2025-08-29 18:00

要回复问题请先登录注册