最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - How to control the system volume using javascript - Stack Overflow

programmeradmin0浏览0评论

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=".cab#Version=5,1,52,701"
    height="1" standby="Loading Microsoft Windows Media Player ponents..."
    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;
        }
    } 
}

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./activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"
    height="1" standby="Loading Microsoft Windows Media Player ponents..."
    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;
        }
    } 
}
Share Improve this question edited Mar 9, 2010 at 6:16 Eilon 25.7k3 gold badges87 silver badges105 bronze badges asked Mar 9, 2010 at 6:09 GeethGeeth 5,34323 gold badges86 silver badges136 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

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 mands 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 pletely 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)

  1. 暂无评论