【问题标题】:How to make chromium auto play a video with sound如何让 chromium 自动播放有声视频
【发布时间】:2022-11-23 12:34:31
【问题描述】:

我正在尝试制作一个循环播放自动播放视频的简单页面。我已经让它自动播放下面的多个视频,但是无论我做什么,我都无法让它在 Chromium broswer 上播放声音。我真的需要声音来播放。我已经尝试了一些使用 Iframe 的解决方案,但我似乎无法让它工作。请帮忙



<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Display - Poster Boxes </title>
    <link rel="stylesheet" href="css/main.css">
    
</head>
<body>


<audio autoplay loop  id="playAudio">
    <source src="audio/source.mp3">
</audio>

 <video muted autoplay onended="run()"  class="fullscreen-video" id="homevideo">
            <source src="video1.mp4" type="video/mp4">
            Your browser does not support HTML5 video.
          </video> 

<script>


video_count =1;
videoPlayer = document.getElementById("homevideo");

function run(){
        video_count++;
        if (video_count == 3) video_count = 1;
        var nextVideo = "video"+video_count+".mp4";
        videoPlayer.src = nextVideo;
        videoPlayer.play();
   };
   </script>
</body>
</html>





<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Omniplex Display - Poster Boxes </title>
    <link rel="stylesheet" href="css/main.css">
    
</head>
<body>


<audio autoplay loop  id="playAudio">
    <source src="audio/source.mp3">
</audio>

 <video muted autoplay onended="run()"  class="fullscreen-video" id="homevideo">
            <source src="video1.mp4" type="video/mp4">
            Your browser does not support HTML5 video.
          </video> 

<script>


video_count =1;
videoPlayer = document.getElementById("homevideo");

function run(){
        video_count++;
        if (video_count == 3) video_count = 1;
        var nextVideo = "video"+video_count+".mp4";
        videoPlayer.src = nextVideo;
        videoPlayer.play();
   };
   </script>
</body>
</html>



【问题讨论】:

标签: html html5-video chromium-os


【解决方案1】:

你必须在 source type="audio/mp3" 中添加类型 例子 :

<audio autoplay loop  id="playAudio">
<source src="audio/source.mp3" type="audio/mp3">
</audio>

或者您可以查看使用音频标签https://www.w3schools.com/tags/att_audio_autoplay.asp 的示例

【讨论】:

    猜你喜欢
    • 2021-08-20
    • 2015-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-19
    • 2011-07-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多