开发者

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.

Problem:

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.

Control:

<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>

Code:

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;
        }
    } 
}


if the audio is still audible once document.mediaPlayer.Volume is set to 0, why don't you set document.mediaPlayer.Settings.mute = true ?

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.

here's some general reference for you of the "most important" parameters supported by Windows Media Player 7 and later:

obj = document.getElementById("mediaPlayer");

  1. Code
    • Parameters or default value
    • Description
  2. obj.Settings.autoStart
    • true
    • Specifies or retrieves a value indicating whether the current media item begins playing automatically.
  3. obj.Settings.baseURL
    • -
    • Specifies the base URL used for relative path resolution with URL script commands that are embedded in media items.
  4. ClosedCaption.captioningID
    • 0
    • Specifies the name of the element displaying the captioning.
  5. obj.Controls.currentMarker
    • 0
    • Specifies the current marker number.
  6. obj.Controls.currentPosition
    • 0
    • Specifies the current position in the media item in seconds.
  7. obj.Settings.defaultFrame
    • -
    • Specifies the name of the frame used to display a URL.
  8. obj.enableContextMenu
    • true
    • Specifies a value indicating whether to enable the context menu, which appears when the right mouse button is clicked.
  9. obj.enabled
    • false
    • Specifies whether the Windows Media Player control is enabled.
  10. obj.fullScreen
    • false
    • Specifies whether video content is played back in full-screen mode.
  11. obj.Settings.invokeURLs
    • true
    • Specifies a value indicating whether URL events should launch a Web browser.
  12. obj.Settings.mute
    • false
    • Specifies if audio is muted.
  13. obj.Settings.PlayCount
    • 1
    • Specifies the number of times a media item will play. Minimum value of one.
  14. obj.Settings.rate
    • 1.0
    • Specifies the playback rate. 0.5 equates to half the normal playback speed, 2 equates to twice.
  15. obj.stretchToFit
    • false
    • Specifies whether video displayed by the control automatically sizes to fit the video window, when the video window is larger than the dimensions of the video image.
  16. obj.uiMode
    • full
    • Specifies which controls are shown in the user interface. Possible values: invisible, none, mini, full.
  17. obj.URL
    • -
    • Specifies the name of the media item to play. You can specify a local filename or a URL.
  18. obj.Settings.volume
    • Last setting
    • Zero specifies no volume and 100 specifies full volume.
  19. obj.Settings.balance
    • false
    • Set balance between left and right speakers. 0 is egual, -100 is full left and 100 is full right.
  20. obj.windowlessVideo
    • false
    • Specifies or retrieves a value indicating whether the Windows Media Player control renders video in windowless mode. When windowlessVideo is set to true, the Player control renders video directly in the client area, so you can apply special effects or layer the video with text. Supported by Windows Media Player for Windows XP or later.


[Edit: remove references to your code]

Not that I have used MediaPlayer before, but why such negative values? According to this

source, Volume should range from 0-100?? which is completely intiutive.

But why are you trying to do this in javascript code when there is a built in volume control int the media player??

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜