Ruby on Rails Friday, June 6, 2014

On Jun 6, 2014, at 2:13 PM, Pierre-Andre M. wrote:

> Believe it or not I'm still fighting with this thing in the rails
> context.
>
> This js works PERFECTLY within its own flat file outside of rails.
> However when I try and incorporate it into rails the video starts right
> from the beginning, I know someone must have solved this one at some
> point:
>
> <!DOCTYPE html>
> <html>
> <head>
> <title>Video.js | HTML5 Video Player</title>
> <link href="/assets/video-js.css" rel="stylesheet" type="text/css">
>
> </head>
> <body>
>
> <video id="example_video_1" class="video-js vjs-default-skin" controls
> preload="auto" width="640" height="264"
> poster="http://video-js.zencoder.com/oceans-clip.png"
> data-setup="{}">
>
> <source src="/assets/test-meeting.m4v" type='video/mp4' />
> </video>
>
> <% javascript_include_tag "play_time" %>
>
> </body>
>
>
> </html>
>
>
> Here is play_time.js
>
> var endtime = 10505.89+10;
> myPlayer= document.getElementById('example_video_1');
> myPlayer.addEventListener('loadeddata', function(){
> example_video_1.currentTime = 10505.89;
> example_video_1.play();
> myPlayer.addEventListener('timeupdate', function(){
> if (example_video_1.currentTime >= endtime) {
> example_video_1.pause();
> }
>
> }, false);
>
> }, false);
>
> Any suggestions? When I use Developer Tools I get:
>
> 0: "Video Error"
> 1: Object
> length: 2
> __proto__: Array[0]
>

By any chance, do you have require tree in your application.js file? Your JavaScript may be getting included twice, and in that case, the error may be coming from the first copy of it (compiled into your application.js file). That's worth checking. If the addEventListener function isn't included last, as you do, then the element it is trying to observe doesn't exist yet, and can't be found. I'm not sure what would happen if you included it twice, but this error might be one possible outcome of that.

Walter

> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/53747ca04a43efe7e3d4643748a9e27b%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/AA853FF4-CD07-4BCB-AA29-2DF94988A338%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment