【问题标题】:how to stop the sound playing automaticly of a video when i launch html file on my browser?当我在浏览器上启动 html 文件时,如何停止自动播放视频的声音?
【发布时间】:2017-11-05 06:17:40
【问题描述】:

我开始学习 html5,我正在尝试使用 jquery mobile 制作视频播放器。我已经搜索了代码并找到了它。我将视频文件放在我的根文件夹中。当我单击“播放”链接时,会弹出一个视频,我可以使用控制按钮播放视频,但问题是,当我尝试在浏览器(mozilla firefox)上启动我的 html 文件时,声音视频自动播放,即使我不点击“播放”链接,也不会弹出视频,声音仍然在播放。请帮助我如何使视频的声音在视频弹出时播放,所以当我在第一次将文件启动到浏览器时不再发出声音。 我用这个:

<!DOCTYPE html> 
<html> 
	<head> 

	<title></title> 
	<meta name="viewport" content="width=device-width, initial-scale=1"> 
	<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.css" />
	<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
	<script src="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.js"></script>
</head> 
<body> 
<div data-role="page" id="utama" data-theme="a" >
  <div data-role="header"  >
    <h1>header</h1>
  </div>  
  <div data-role="content">
    <p></p>
	<br/>
	<a href="#dialog" data-rel="dialog">play </a>
  </div>  
  <div data-role="footer" >
    <h4> &copy </h4>
  </div>
</div>  
<div data-role="page" id="dialog">
  <div data-role="header"  >
    <h1>video</h1>
  </div>  
  <div data-role="content">
	
	<iframe id="player_1" src="abjad_a.mp4" width="540" height="304" frameborder="0" webkitallowfullscreen=""></iframe>
	<a  data-rel="back"> back</a>

  </div>  
  <div data-role="footer" >
    <h4>&copy </h4>
  </div>
</div>
</div>
</body>
</html>

`

【问题讨论】:

  • 不要发布代码截图。 Edit你的问题包括代码。
  • 谢谢,我已经改了。

标签: javascript html iframe html5-video


【解决方案1】:

你可以使用HTML5 Video

以 HTML 格式播放视频 在 HTML5 之前,视频只能在带有插件(如 flash)的浏览器中播放。

HTML5 元素指定了在网页中嵌入视频的标准方式。

您可以通过 javascript HTML Audio/Video DOM Reference 自定义视频播放器,而不是 iframe

见 sn-p :

var vid = document.getElementById("video_mute");

vid.muted = true;//mute video on window load

function enableMute() { 
    vid.muted = true;
} 

function disableMute() { 
    vid.muted = false;
} 

function checkMute() { 
    alert(vid.muted);
}
<video width="400" id="video_mute" controls>
  <source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
  Your browser does not support HTML5 video.
</video>
<button onclick="enableMute()" type="button">Mute sound</button>
<button onclick="disableMute()" type="button">Enable sound</button>
<button onclick="checkMute()" type="button">Check muted status</button><br>

<p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>

【讨论】:

  • 感谢您帮助我。我真的很感激。
  • 如果我使用 iframe 会怎样?当我将文件启动到浏览器时,有什么方法可以停止自动播放的声音?
  • 是的,你可以使用HTMLIFrameElement.mute()
  • 谢谢你再次帮助我。老实说,我不知道如何使用语法。如果我使用网站上的启动视频播放器语法,我应该把语法放在哪里:demos.jquerymobile.com/1.4.0/popup-iframe/#&ui-state=dialog
猜你喜欢
  • 1970-01-01
  • 2014-11-21
  • 1970-01-01
  • 2023-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-28
相关资源
最近更新 更多