none
stop playing video through javascript

    Question

  • I am using this code to play the media using windows media player . I passed the respective parameters and getting the results ' '; I tried to stop the playing video using document.MediaPlayer.Stop() This works fine for IE but doesnot work for firefox what do I need to do ?

     

    '<OBJECT ID="MediaPlayer" CLASSID=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 CODEBASE=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715 standby="Loading Microsoft Windows Media Player components..." TYPE="application/x-oleobject" width="' + width + '" height="' + height + '"> <PARAM NAME="FileName" VALUE="' + url + '"><PARAM NAME="AutoStart" VALUE="' + autostart + '"><PARAM NAME="ShowGoToBar" VALUE="1"><PARAM NAME="ShowControls" VALUE="1"><param name="uimode" value="none" /><Embed type="application/x-mplayer2" MAYSCRIPT pluginspage="http://www.microsoft.com/windows/windowsmedia/" filename="' + url + '" Name=MediaPlayer ShowControls=1 ShowGoToBar=1 AutoStart="' + autostart + '" ShowDisplay=1 ShowStatusBar=1 width="' + width + ' height=' + height + '> </embed></OBJECT>';

    Tuesday, December 02, 2008 1:21 AM

Answers

  •  IE and FFox use different plugins for WMP. You need to determine which browser is being used, and then supply relevant plugin such as:-

     <body style="background:black">

    <div id="playdiv1" style="position:absolute;left:419px;top:0px;height:44px;"></div>

    <script type="text/javascript">

    if (-1 != navigator.userAgent.indexOf("MSIE")) {

    document.getElementById("playdiv1").innerHTML = '<object id="Player" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" style="position:absolute;top:10px;width:64px;height:54px;filter: progid:DXImageTransform.Microsoft.BasicImage(grayScale = 1 )" ><param name="autoStart" value="false"/><param name="UImode" value="none"/><param name="stretchtofit" value="true"/><param name="volume" value="100"/><param name="Url" value="Elvis Presley - Way Down.mp3"/><param name="windowlessVideo" value="true"/></object>';

    }

    else if (-1 != navigator.userAgent.indexOf("Firefox")) {

    document.getElementById("playdiv1").innerHTML = '<object id="Player" type="application/x-ms-wmp" Width="64px" Height="64px" Url="Elvis Presley - Way Down.mp3"><param name="autoStart" value="false"/><param name="UImode" value="none"/><param name="volume" value="100"/><param name="windowlessVideo" value="true"/></object>'; var hitme = "H:\\Sound\\rkive\\cd lib1\\";

    Player = document.getElementById("Player");

    }

    </script>

    </body>

     Then the syntax to stop etc is:-

    document.getElementById("Player").controls.stop();

    Regards, Marc.

    Wednesday, December 03, 2008 5:06 PM

All replies

  • Try using the GetElementById instead:

    document.getElementById('MediaPlayer').Stop();
     
    Tuesday, December 02, 2008 2:12 AM
  • Well i did this for my player and it works

    in firefox browser an image[film1.jpg] would show, if u click on it, it would play. stop also works

    <head runat="server">
        <title></title>
    <script type="text/javascript">
        function ShowMe(PlayerId) {
            var elm = document.getElementById(PlayerId);
            elm.style.display = 'block';

        }
        function HideMe(PlayerId) {
            var elm = document.getElementById(PlayerId);
            elm.style.display = 'none';
        }
      </script>
    </head>

    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server" />
            <div style="width:176px;height:104px;background-image:url('http://mysite/Images/Others/film1.jpg');
                    cursor:hand;"
                    onclick="ShowMe('div35b251d');
                    player35b251d.controls.Play()" >
                    <div id="div35b251d" style="display:none;">
                    <object classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'
                    id='player35b251d'
                    width='174'
                    height='104'
                    standby='Please wait while the object is loaded...'>
                    <param name='url' value='http://mysite/Upload/film1.wmv' />
                    <param name='src' value='http://mysite/Upload/film1.wmv' />
                    <param name='TransparentAtStart' value='0' />
                    <param name='AutoStart' value='0' />
                    <param name='CurrentMarker' value='0' />
                    <param name='Balance' value='0' />
                    <param name='CurrentPosition' value='0' />
                    <param name='showcontrols' value='false' />
                    <param name='enablecontextmenu' value='false' />
                    <param name='fullscreen' value='False' />
                    <param name='mute' value='false' />
                    <param name='PlayCount' value='1' />
                    <param name='rate' value='1.0' />
                    <param name='uimode' value='none' />
                    <param name='volume' value='100' />
                    <embed type='application/x-mplayer2'
                    pluginspace = 'http://www.microsoft.com/Windows/MediaPlayer/'
                    name='player35b251d' ShowStatusBar='0' EnableContextMenu='0' autostart='0'
                    width = '174' height = '129' loop='false'
                    transparentatstart='true' src='http://mysite/Upload/film1.wmv' />
                    </object>
                   
                    </div>
            </div>
            <br />
            <div style="text-align:left;">
                    <img alt="" src=" http://mysite/Images/Others/microsite-video_play.gif "
                    title="Play" style="width: 82px;cursor:hand;height: 17px;padding-top:5px;"
                    onclick="ShowMe('div35b251d');player35b251d.controls.Play()" />
                    <img alt="" src=" http://mysite/Images/Others/stop.png "
                    title="Stop" style="width: 23px;cursor:hand;height: 17px;padding-top:5px;"
                    onclick="HideMe('div35b251d');player35b251d.controls.pause()";player35b251d.controls.stop(); />
                    </div>
        </div>
        </form>
    </body>

    for securite reasons i change it to myste from its original name, but it works

    and if the post was helpful then please 'Mark as Answer' - many thanks

    Sharker Khaleed Mahmud
    Software Developer
    (MCP,MCTS,MCPD[web])

    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.

    Tuesday, December 02, 2008 2:21 AM
  • thanks , This logic works when there is image or file.

    But for media 

    setting display=none only hide the video but the sound of video is heard in the background

    So I need to stop the playing video . I tried by using getElement by Id as well

    but I think there is no method support called  stop () in javascript.How do I proceed In this scenario

     

    Tuesday, December 02, 2008 5:06 AM
  • This play() and Pause does not work in the Firefox browser

    Do u have any Solution?? 

    Tuesday, December 02, 2008 6:02 AM
  •  IE and FFox use different plugins for WMP. You need to determine which browser is being used, and then supply relevant plugin such as:-

     <body style="background:black">

    <div id="playdiv1" style="position:absolute;left:419px;top:0px;height:44px;"></div>

    <script type="text/javascript">

    if (-1 != navigator.userAgent.indexOf("MSIE")) {

    document.getElementById("playdiv1").innerHTML = '<object id="Player" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" style="position:absolute;top:10px;width:64px;height:54px;filter: progid:DXImageTransform.Microsoft.BasicImage(grayScale = 1 )" ><param name="autoStart" value="false"/><param name="UImode" value="none"/><param name="stretchtofit" value="true"/><param name="volume" value="100"/><param name="Url" value="Elvis Presley - Way Down.mp3"/><param name="windowlessVideo" value="true"/></object>';

    }

    else if (-1 != navigator.userAgent.indexOf("Firefox")) {

    document.getElementById("playdiv1").innerHTML = '<object id="Player" type="application/x-ms-wmp" Width="64px" Height="64px" Url="Elvis Presley - Way Down.mp3"><param name="autoStart" value="false"/><param name="UImode" value="none"/><param name="volume" value="100"/><param name="windowlessVideo" value="true"/></object>'; var hitme = "H:\\Sound\\rkive\\cd lib1\\";

    Player = document.getElementById("Player");

    }

    </script>

    </body>

     Then the syntax to stop etc is:-

    document.getElementById("Player").controls.stop();

    Regards, Marc.

    Wednesday, December 03, 2008 5:06 PM