Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
78
rated 0 times [  83] [ 5]  / answers: 1 / hits: 15551  / 12 Years ago, thu, november 22, 2012, 12:00:00

So following JW Player's I can get a video to load (obviously) it looks like this:



<script type=text/javascript src=/scripts/jwplayer.js></script>
<div id=myElement>Loading the player ...</div>
<script type=text/javascript>
jwplayer(myElement).setup({
file: /uploads/example.mp4,
height: 360,
image: /uploads/example.jpg,
width: 640
});
</script>


I'm trying to accomplish something to this effect to load a video inside of a modal once that modal is triggered (using jQuery):



$(body).on('click', '[data-toggle=modal]', function(e){
var vid = $(this).attr('data-video');
jwplayer(videoElement).setup({ file: vid, width: 540 });
jwplayer(videoElement).play();
});


However I'm getting the error: Uncaught TypeError: Cannot call method 'setup' of null



I've tried the other following (probably horrible) ideas I've had:



$(#videoElement).jwplayer.setup({ file: vid, width: 540 });


and



var $jwplayer = jwplayer();
$(body).on('click', '[data-toggle=modal]', function(e){
$jwplayer(videoElement).setup({ file: vid, width: 540 });
}


However all yield the same result of Cannot call method 'setup' of null



Any pointers would be greatly appreciated.


More From » jquery

 Answers
13

you don't have a videoElement on the page only myElement:



<div id=myElement>Loading the player ...</div>
<script type=text/javascript>
jwplayer(myElement).setup({
file: /uploads/example.mp4,
height: 360,
image: /uploads/example.jpg,
width: 640
});
</script>


you must use:



jwplayer(myElement).setup({ file: vid, width: 540 });

[#81854] Wednesday, November 21, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
vanessag

Total Points: 170
Total Questions: 98
Total Answers: 88

Location: El Salvador
Member since Sun, Sep 12, 2021
3 Years ago
;