datocp
V2EX  ›  问与答

求教用网页在 android 4.2.1 循环播放音频的问题

  •  
  •   datocp · May 9, 2023 · 1389 views
    This topic created in 1160 days ago, the information mentioned may be changed or developed.

    公司之前使用 wps 投影宝播放 ppt 方式显示欢迎屏幕,但这 app 最近老崩溃就尝试使用 web 页面解决。

    最终拼拼凑凑,终于可以了。可是在电视里用飞视时发现音频循环到第二遍时 app 就自动退出。使用 via 浏览器还算好,像是 3 分钟的背景音乐能循环个 3 遍,但是最终没声音。而这段代码在 android12 手机里的 via 浏览器是可以不断循环的。

    所以想请教各位高手有其他解决方法嘛。

    问题 1.android 4.2.1 是不是无法做到刷新页面就自动播放音频的嘛,不然还可以尝试刷新方式。

    目前就是刷新一下,点击一下开始播放音频,但是音频无法做到不断的循环。

    <html> <head> <style> html, body { height: 100%; }

    html { display: table; margin: auto; }

    body { display: table-cell; vertical-align: middle; } </style>

    </head> <body> <script> document.write(' '); </script>

    <audio src="source/ww.mp3" id="audios" autoplay preload loop="loop"></audio>

    <script> function audioAutoPlay(id){ var audio = document.getElementById(id), play=function(){ audio.play(); document.removeEventListener("click",play, false); }; audio.play(); document.addEventListener("click",play,false); } audioAutoPlay('audios'); </script> </body> </html>
    Supplement 1  ·  May 9, 2023
    <html>
    <head>
    <style>
    html, body {
    height: 100%;
    }

    html {
    display: table;
    margin: auto;
    }

    body {
    display: table-cell;
    vertical-align: middle;
    }
    </style>
    </head>
    <body>
    <script>
    document.write(' <img src="laibin/1.png?v=' + new Date().getTime() + '" alt="" width="1920" height="1080"/>');
    </script>

    <audio src="source/ww.mp3" id="audios" autoplay preload loop="loop"></audio>
    <script>
    function audioAutoPlay(id){
    var audio = document.getElementById(id),
    play=function(){
    audio.play();
    document.removeEventListener("click",play, false);
    };
    audio.play();
    document.addEventListener("click",play,false);
    }
    audioAutoPlay('audios');
    </script>

    </body>
    </html>

    <script>
    $(function(){
    var myAudio = document.getElementById('audio');
    myAudio.addEventListener('ends',loopAudio,false);

    })
    function loopAudio(){
    var myAudio = document.getElementById('audio');
    myAudio.play();
    }
    </script>
    2 replies    2023-05-09 13:44:27 +08:00
    whyrookie
        1
    whyrookie  
       May 9, 2023
    视频这块没有在这么低版本上适配过,推荐一个思路,如果不在意安装包大小,可以使用 GeckoView 替代系统的 Webview 。
    datocp
        2
    datocp  
    OP
       May 9, 2023
    @whyrookie

    谢谢大家的关注,网络上的讨论说到 android 低版本对 mp3 的支持问题。通过 foobar2000 将这首背景音乐 mp3 转换成 ogg 格式。使用 via 浏览器从 13:01 一直循环播放到 13:40 ,看起来这个问题已经解决了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   858 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 21:48 · PVG 05:48 · LAX 14:48 · JFK 17:48
    ♥ Do have faith in what you're doing.