admin管理员组

文章数量:1290137

here is part of my code:

var myPlayer = document.getElementById("example_video_1");
        if (content=="play()") {
                $('title').html("screen:"+content);
            myPlayer.play();
        }
        if (content=="pause()") {
                $('title').html("screen:"+content);
            myPlayer.pause();
        }
        if (content.indexOf("src(")!=-1) {
            var videoMP4 = content.replace("src(","").replace(")","");
            myPlayer.src({type: "video/mp4", src:videoMP4});
            // {type: "video/webm", src:videoMP4.replace(".mp4", ".webm")},
            //  {type: "video/ogg", src:videoMP4.replace(".mp4", ".ogv")}
            // ]
            myPlayer.play();
        }

the pause function and the play function work as expected. But for some reason when the code reaches the

myPlayer.src({type: "video/mp4", src:videoMP4}); 

i get an error in my console :

Uncaught TypeError: Property 'src' of object #<HTMLVideoElement> is not a function 

any idea why this happens?

here is part of my code:

var myPlayer = document.getElementById("example_video_1");
        if (content=="play()") {
                $('title').html("screen:"+content);
            myPlayer.play();
        }
        if (content=="pause()") {
                $('title').html("screen:"+content);
            myPlayer.pause();
        }
        if (content.indexOf("src(")!=-1) {
            var videoMP4 = content.replace("src(","").replace(")","");
            myPlayer.src({type: "video/mp4", src:videoMP4});
            // {type: "video/webm", src:videoMP4.replace(".mp4", ".webm")},
            //  {type: "video/ogg", src:videoMP4.replace(".mp4", ".ogv")}
            // ]
            myPlayer.play();
        }

the pause function and the play function work as expected. But for some reason when the code reaches the

myPlayer.src({type: "video/mp4", src:videoMP4}); 

i get an error in my console :

Uncaught TypeError: Property 'src' of object #<HTMLVideoElement> is not a function 

any idea why this happens?

Share Improve this question asked Jan 9, 2013 at 14:55 tk66tk66 2847 silver badges21 bronze badges 1
  • myPlayer.src({ type: "video/mp4", src: "example./path/to/video.mp4" }); this is the example from the documentation site – tk66 Commented Jan 9, 2013 at 14:58
Add a ment  | 

3 Answers 3

Reset to default 7

var myPlayer = document.getElementById("example_video_1");

returns a standard HTML video element. You need to use:

var myPlayer = _V_("example_video_1");

to get the VideoJS object.

Change the source and type like:

myPlayer.setAttribute("src", videoMP4);
myPlayer.setAttribute("type", "video/mp4");
myPlayer.load();  # Force video refresh...

src is a "DOMString", not a function.

See https://developer.mozilla/en-US/docs/DOM/HTMLMediaElement

Reflects the src HTML attribute, containing the URL of a media resource to use. Gecko implements a similar functionality is available for streams: mozSrcObject.

myPlayer.src = videoMP4;

If you want to specify multiple (typed) sources you need to create DOM elements as children of myPlayer.

本文标签: javascriptvideojs src() function not recognizedStack Overflow