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

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></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="javascript:void(0);" class="play" onclick='play()'>Play</a>
<a href="javascript:void(0);" class="play" onclick='pause()'>Pause</a>
</body>


<script type="text/javascript">
$(document).ready(function(){
var player = document.getElementById("vlcp");
$('.play').click(function(){
var thisvalue = $(this).html();
if(thisvalue=="Play"){
alert("Play");
}else{
if(thisvalue=="Pause"){
alert("Pause");
}
}
});
});
</script>

Need Your Help

Rails - Automatic create admin if there are no admin and login

ruby-on-rails passwords bcrypt

I have a sign in of Admins, but when the databases are empty you can't enter because there are no admins user, so i'm trying to create an admin user in the controller, but is not very secure for ob...

Custom Lists: how to retrieve 3 most recent item submissions

list sharepoint-2007 caml

I have currently 2 custom SharePoint lists. One represents questions, the other one answers.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.