Question

So my question is how do I start a movie with a call to a javascript / jquery function?

Background:

I have an object in my html that embeds is a .mov file like so:

<object CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="100%" height="100%" class="movie1" id="movie1ie">
                <param name="src" value="movies/test.mov">
                <param name="autoplay" value="false">
                <param name="loop" value="false">
                <param name="controller" value="false">
                <!--[if !IE]>-->
                <object type="video/quicktime" data="movies/test.mov" width="100%" height="100%" class="movie1" id="movie1">
                    <param name="autoplay" value="false">
                    <param name="loop" value="false">
                    <param name="controller" value="false">
                </object>
                <!--<![endif]-->
            </object>

And it seems to be okay, until I want to play the movie with a call to javascript. I am using jQuery so I tried this from within a function:

function startMovie(whom){
    var playIt = 'movie'+ whom;
    $('#' + playIt).get(0).play();
}
//and call the function
startMovie(1);

But then I get this error:

Uncaught TypeError: Object #<HTMLObjectElement> has no method 'play' 

Weird, but I'm no jQuery ninja so I tried to call it using good ole javascript:

function startMovie(1){
    var playIt = 'movie'+ whom;
    document.getElementById(playIt).Play();
}

But now I get the following error in my console:

Uncaught Error: Error calling method on NPObject. 

Which is very wierd, since if I put the following into my console the movie will start playing without errors:

document.getElementById('movie1').Play()

FWIW I am using Chrome on a Mac and the files are running on the local machine (no server).

Was it helpful?

Solution

function startMovie(whom){
    var playIt = 'movie'+ whom;
    document.getElementById(playIt).Play();
}
startMovie('1');

Try that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top