using jquery to play pause embedded vlc player

I embedded vlcplayer in html and wanted to play ,pause the video .So I created a javascript file and coded some functions

<head>
<script type="text/javascript"  src="jquery-1.7.1.min.js" ></script>
<script type="text/javascript"  src="vctrl.js" ></script>
</head>
<body>
<embed id="vlcp" type="application/x-vlc-plugin" name="VLC"  autoplay="no" loop="no" volume="100" width="640" height="480" target="test.flv">
</embed>
<a href="#" onclick='play()'>Play</a>
<a href="#" onclick='pause()'>Pause</a>
</body>

The javascript file has

$(document).ready(function(){
    var player = document.getElementById("vlcp");
    var play = function(){
        if(player){
            alert("play");
        }
    };

    var pause = function(){
        if(player){
            alert("pause");
        }
    };        
}
);

When I click on the play link ,the alert box doesn't appear..Is the way I have given the onclick value wrong?

Answers


Your functions play and pause are defined as local variable of the function you give to the ready function. So they're not visible to the DOM objects.

A solution could be to declare them in an usual way (or window.play = function...).

But the correct way using jquery is to use jquery binding functions :

    <head>
    <script type="text/javascript"  src="jquery-1.7.1.min.js" ></script>
    <script type="text/javascript"  src="vctrl.js" ></script>
    </head>
    <body>
    <embed id="vlcp" type="application/x-vlc-plugin" name="VLC"  autoplay="no" loop="no" volume="100" width="640" height="480" target="test.flv">
    </embed>
    <a id=playbutton href="#">Play</a>
    <a id=pausebutton href="#">Pause</a>
    </body>



    $(document).ready(function(){
        var player = document.getElementById("vlcp");
        $('#playbutton').click(function(){
            if(player){
                alert("play");
            }
        });

        $('#pausebutton').click(function(){
            if(player){
                alert("pause");
            }
        });        
    }
    );  

Need Your Help

Use data from Node.js function

javascript node.js function asynchronous express

I am learning to work with NodeJS and I came with a problem. getCurrentWeather() is asynchronous function which loads instantly when I start the app, and writes data to variables. When I use those