Results 1 to 6 of 6

Thread: [RESOLVED] Accessing Video Clip Time Mark During Play for Slideshow

  1. #1
    Join Date
    Jul 2010

    resolved [RESOLVED] Accessing Video Clip Time Mark During Play for Slideshow

    Can scripting be used to access the time mark during play so that images can be rolled next to it to make a slideshow?

  2. #2
    Join Date
    Mar 2005
    Behind you...
    While this can be done, you won't have full cross-browser compatibility (for some older versions of IE and some mobile browsers).

    Through the use of the HTML5 <video> tag you can play the video on your page and access its time mark location through javascript.
    HTML Code:
    <video id="vidElem" width="640" height="480">
      <source src="movie.webm" type="video/webm" />
      <source src="movie.mp4" type="video/mp4">
      <source src="movie.ogg" type="video/ogg">
      Your browser does not support the video tag.
    var $video = document.getElementById('vidElem');
    $video.addEventListener("canplay", _InitSync, false);
    function _InitSync() {
      $video.addEventListener("timeupdate", _SyncSlides, false);
    function _SyncSlides() {
      $curTime = $video.currentTime;
    To be honest I haven't tested this code personally, but all of it should be valid. In the end you will have a variable with the current time mark of the video that will be updated as the video plays. Also I'm not even sure the '_InitSync()' function was a necessary step but I added it more or less to be safe. Basically this will wait for the video element to be ready and then once it is, it will add an event that fires every time the video changes it time marker. In this final function you would simply add some code that would change your slides based on the value of $curTime.

    Let me know if this resolves your issue or not.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  3. #3
    Join Date
    Jul 2008
    urbana, il
    that's going to add a new watcher every time the video loads, when it only needs to happen once.
    not sure if it will break the simple demo, but it's something to watch for.
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

  4. #4
    Join Date
    Mar 2005
    Behind you...
    The _InitSync() does really only need to happen once and that's why I said it probably wasn't really even necessary. There are certainly better ways to set that up. You would just need to make sure it sets the timeupdate event watcher after the video is ready and loaded. The timeupdate event part is fine though; it's typically used for displaying the video time in a custom interface/custom controls and seems to fit well for this situation.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  5. #5
    Join Date
    Jul 2010
    Quote Originally Posted by Sup3rkirby View Post
    Let me know if this resolves your issue or not.
    Okay, this code seems to be working, although I will be doing more optimizing to get the right features.

    After reading about the media object (Audio, Video elements) interface at MSDN and elsewhere to learn
    more about object properties, methods, and the events affecting them (thanks to your guidance),
    I have slightly modified your functions. The modifications basically use anonymous functions to define
    the handlers and pass on arguments into the event handlers themselves.

    Global scope script variables are initialized in that scope, namely array of numbers (in seconds)
    for the time marks at which I want an image to change in the slideshow document block (a P element,
    in this case). Images are basically rotated in and out using DOM methods ( replaceChild() ).
    The initialize() function is used after the body is loaded to intiailize the rest of the global variables
    that are DOM document nodes. Images for the slideshow are also pre-loaded into an array. Many of
    the numerical constants (e.g., "500px") worked for my presentation, and should be altered for another's
    particular document styling/spacing.

    This particular set up does not "go backwards" perhaps in case the user does a backward seek on the
    playback of the control, but that is easy enough to code in.

    The reason I making this slideshow is that it is a ballet show with many dancers in the scene.
    I am pointing out a particular dancer (this is an "Arts Resume" and the web page link will be sent to
    dance instructors) but snapshotting a video instance, putting a simple arrow in Photoshop to
    point out the dancer, it allows the instructors to identify the dancer, whom they have never met.

    HTML Code:
    <script type="text/javascript">
    var slidesBlock, // DOM element containing slideshow images
       timeMarks = [ 50, 70, 80, 170, 200, 250 ],
       timeMarkIndex = 0,
       currentTimeMark = timeMarks[timeMarkIndex],
       preloadedImages = [];
    function initialize() {
       var i, img, index,
          myVid = document.getElementById("ballet-vid"),
          slidesBlock = document.getElementById("slideshow");
       if (typeof myVid.addEventListener == "function")
          myVid.addEventListener("canplay", function () {
                 initSync(myVid, slidesBlock); }, false);
      else if (typeof myVid.attachEvent == "function")
          myVid.attachEvent("oncanplay", function () {
                 initSync(myVid, slidesBlock); } );
      // preload images
      for (i = 0; i < timeMarks.length; i++) {
         img = new Image();
         img.alt = "still #" + (i + 1) + " of My Video";
         index = "0";
         if (i < 9)
           index += i + 1;
           index = i + 1
         img.src = "StillsOfMyVideo-" + index + ".png";
         img.style.width = "500px";
    function initSync(vidClip, slideShowBlock) {
        if (typeof vidClip.addEventListener == "function")
           vidClip.addEventListener("timeupdate", function () {
                    syncSlides(vidClip, slideShowBlock); }, false);
        else if (typeof vidClip.attachEvent == "function")
           vidClip.attachEvent("ontimeupdate", function () {
                   syncSlides(vidClip, slideShowBlock); } );
    function syncSlides(vidClip, slideShowBlock) {
        if (vidClip.currentTime > currentTimeMark) {
           slideShowBlock.replaceChild(preloadedImages[timeMarkIndex++], slideShowBlock.firstChild);
           currentTimeMark = timeMarks[timeMarkIndex];
    <body onload="initialize();">
    <p style-"margin:0;">
    <video controls preload id="ballet-vid" poster="poster.png"
    style="float:left;margin:0 1.5em 0.5em -10%;border:1px solid lime;">
       style="border:1px solid lime;padding:0;margin:0;">
    	<source src="myvid.mpg" type="video/mpeg">
    	<source src="myvid.mp4" type="video/mp4">
    	<source src="myvid.webm" type="video/webm">
    	<object data="myvid.mpg" type="video/mpeg" width="750" height="600">
    	  <embed src="myvid.mpg" type="video/mpeg" width="750" height="600">
    <p id="slideshow"><img src="poster.png" alt="initial image of slideshow">

  6. #6
    Join Date
    Jul 2010
    I am marking this resolved since the solution offered by Sup3rkirby discusses the timeupdate event, and that is the essential answer to the problem.

    I have significantly modified Sup3kirby's original code however.

    For one thing, I have eliminated the canplay event handler as the intermediate invoking the timeupdate event. It is not really necessary. Whenever the canplay handler is called, it would continually attempt code to add the timeupdate event handler, and that is not necessary it seems. I found that removing this intermediate code (the canplay handler) has the same wanted effect.

    As to my timeupdate handler, it is responsible for a number of actions in my slideshow program:

    • It rotates images (as objects) in and out of a DOM block (div or p) element as the first (and only) child of the element, based on the time value continually updated by the timeupdate handler
    • It also "rotates" text to change the caption: in my particular strategy, I have a number of div elements all of whose display is set to "none" during document initialization. As a time mark is reached, a display is set to "" (empty string), as good as displaying the element by its default styling.
    • For a couple of elements, the text is small enough that I do a replaceChild() methods on text nodes, which are created in the handler
    • I have created a seeked handler as well: what if the user changes the playback position control to an earlier or later time? In that case the appropriate slide and explanatory text must be updated. It basically runs a for-loop to look at an array of times (integer values in seconds) to find the correct array index position, and uses that to put up the photos and text.

    Debugging an event handler in general can be a pain. And debugging one where the object generating events is an audio or video playback has proven difficult still:

    For example, I have set a breakpoint inside the timeupdate and seeked handler code because I want to check problems with code logic.

    The CONTINUING PROBLEM is that while the breakpoint is reached, the media object (video) continues playback. I have put a videoObj.pause() just inside the two event handlers at the start, and a video.play() as the last statement in those handlers. But as the debugger reaches the breakpoint in the timeupdate handler, just after executing the videoObj.pause() method, the video playback has not paused at all...it continues!

    I cannot imagine what event is taking over and forcing the media object to execute a .play() method.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.10212 seconds
  • Memory Usage 2,913KB
  • Queries Executed 15 (?)
More Information
Template Usage (35):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_code
  • (2)bbcode_html
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (73):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates