如何使用javascript控制系统音量 [英] How to control the system volume using javascript
问题描述
我正在使用媒体播放器播放音频和视频。我正在创建自己的按钮来增加和减少媒体播放器的音量。工作也很好。
I am using media player to play audio and video. I am creating own button to increase and decrease the volume of the media player. working fine too.
问题:
即使在达到0%音量后也会发出声音。如果播放器音量增加,系统音量也会增加。可能吗。如何实现这一任务。
Even after reaches 0% volume its audible. If the player volume increase the system volume also be increased. Is it possible. How to achieve this task.
控制:
<object id="mediaPlayer" classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"
height="1" standby="Loading Microsoft Windows Media Player components..."
type="application/x-oleobject" width="1">
<param name="fileName" value="" />
<param name="animationatStart" value="true" />
<param name="transparentatStart" value="true" />
<param name="autoStart" value="true" />
<param name="showControls" value="true" />
<param name="volume" value="70" />
</object>
代码:
function decAudio() {
if (document.mediaPlayer.Volume >= -1000) {
var newVolume = document.mediaPlayer.Volume - 100;
if (newVolume >= -1000) {
document.mediaPlayer.Volume = document.mediaPlayer.Volume - 100;
} else {
document.mediaPlayer.Volume = -1000;
}
}
}
推荐答案
如果 document.mediaPlayer.Volume
设置为 0
后音频仍然可以听到,为什么要''你设置
document.mediaPlayer.Settings.mute = true
?
if the audio is still audible once document.mediaPlayer.Volume
is set to 0
, why don't you set
document.mediaPlayer.Settings.mute = true
?
你也确定 document.mediaPlayer.Settings.Volume
不是正确的引用而不是 document.mediaPlayer.Volume
?看起来你正试图直接访问参数/属性值,而不是通过mediaplayer的javascript(或jscript)接口。
also are you sure that document.mediaPlayer.Settings.Volume
isn't the correct reference instead of document.mediaPlayer.Volume
? it looks like you're trying to access the parameter/property value directly instead of going through the mediaplayer's javascript (or jscript) interface.
这里有一些关于你的一般参考Windows Media Player 7及更高版本支持的最重要参数:
here's some general reference for you of the "most important" parameters supported by Windows Media Player 7 and later:
obj = document.getElementById(mediaPlayer);
-
代码
-
参数
或默认值 -
描述
-
Code
Parameters
or default valueDescription
-
true
- 指定或检索一个值,该值指示当前媒体项是否开始自动播放。
- -
- 使用嵌入在媒体项中的URL脚本命令指定用于相对路径解析的基本URL。
-
0
- 指定显示字幕的元素的名称。
-
0
- 指定当前标记号。
-
0
- 指定当前位置在几秒钟内在媒体项目。
- -
- 指定用于显示网址的框架的名称。
-
true
- 指定一个值,该值指示是否启用上下文菜单,单击鼠标右键时会显示该菜单。
-
˚F alse
- 指定是否启用Windows Media Player控件。
-
false
- 指定是否以全屏模式播放视频内容。
-
true
- 指定一个值,指示URL事件是否应启动Web浏览器。
-
false
- 指定音频是否静音。
-
1
- 指定次数媒体项目将播放。最小值为1。
-
1.0
- 指定播放速率。
0.5相当于正常播放速度的一半,2相当于两次。
-
false
- 指定当视频窗口大于视频图像的尺寸时,控件显示的视频是否自动调整大小以适合视频窗口。
-
full
- 指定在用户界面中显示哪些控件。
可能的值:不可见,无,迷你,满。
- -
- 指定要播放的媒体项目的名称。
您可以指定本地文件名或URL。
- 上次设置
- 零指定无音量,100指定全音量。
-
false
- 设置左右扬声器之间的平衡。 0是正常的,-100是完整的左边,100是完整的。
-
false
- 指定或检索一个值,指示Windows Media Player控件是否以无窗口模式呈现视频。
当windowlessVideo设置为true时,Player控件直接在客户区域中呈现视频,因此您可以应用特殊效果或使用文本对视频进行分层。
受Windows Media Player for Windows XP或更高版本支持。
这篇关于如何使用javascript控制系统音量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!