Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    806
    Thanks
    42
    Thanked 6 Times in 5 Posts

    alert as a time delay

    This is a bit odd. The sound will play and then go to the video (which is what I want) but only if I include the alert!

    Code:
    soundManager.play('scratch','../../media/mp3/scratch.mp3');
    alert("why do you need me?");
    document.writeln("<object classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\" width=\"480\" height=\"336\">");
    document.writeln("<param name=\"src\" value=\"file:///"+driveletter+":/MEDIA/VIDEO/Lesson27.mov\">");
    document.writeln("<embed width=\"480\" height=\"336\" type=\"video/quicktime\" pluginspage=\"http://www.apple.com/quicktime/download/\" src=\"file:///"+driveletter+":/MEDIA/VIDEO/Lesson27.mov\" controller=\"true\" autoplay=\"true\" scale=\"aspect\"></embed>");
    document.writeln("<param name=\"controller\" value=\"true\">");
    document.writeln("<param name=\"autostart\" value=\"true\">");
    document.writeln("<param name=\"scale\" value=\"aspect\">");
    document.writeln("</object>");
    }}
    If I take out the alert, the sound gets bypassed.

    How can I get rid of the alert and have the sound play then go to the video?

    Something about giving the sound enough time to play?
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,734
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by tpeck View Post
    This is a bit odd. The sound will play and then go to the video (which is what I want) but only if I include the alert!

    Code:
    soundManager.play('scratch','../../media/mp3/scratch.mp3');
    alert("why do you need me?");
    document.writeln("<object classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\" width=\"480\" height=\"336\">");
    document.writeln("<param name=\"src\" value=\"file:///"+driveletter+":/MEDIA/VIDEO/Lesson27.mov\">");
    document.writeln("<embed width=\"480\" height=\"336\" type=\"video/quicktime\" pluginspage=\"http://www.apple.com/quicktime/download/\" src=\"file:///"+driveletter+":/MEDIA/VIDEO/Lesson27.mov\" controller=\"true\" autoplay=\"true\" scale=\"aspect\"></embed>");
    document.writeln("<param name=\"controller\" value=\"true\">");
    document.writeln("<param name=\"autostart\" value=\"true\">");
    document.writeln("<param name=\"scale\" value=\"aspect\">");
    document.writeln("</object>");
    }}
    If I take out the alert, the sound gets bypassed.

    How can I get rid of the alert and have the sound play then go to the video?

    Something about giving the sound enough time to play?
    Try wrapping the code for the video in a function with setTimeout with a couple of seconds delay.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    806
    Thanks
    42
    Thanked 6 Times in 5 Posts
    It's weird Philip.

    Code:
    soundManager.play('scratch','../../media/mp3/scratch.mp3');
    alert("why do you need me?");
    vid2();
    //setTimeout('vid2()',3000);
    }}
    
    function vid2(){
    document.writeln("<object classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\" width=\"480\" height=\"336\">");
    document.writeln("<param name=\"src\" value=\"file:///"+driveletter+":/MEDIA/VIDEO/Lesson27.mov\">");
    document.writeln("<embed width=\"480\" height=\"336\" type=\"video/quicktime\" pluginspage=\"http://www.apple.com/quicktime/download/\" src=\"file:///"+driveletter+":/MEDIA/VIDEO/Lesson27.mov\" controller=\"true\" autoplay=\"true\" scale=\"aspect\"></embed>");
    document.writeln("<param name=\"controller\" value=\"true\">");
    document.writeln("<param name=\"autostart\" value=\"true\">");
    document.writeln("<param name=\"scale\" value=\"aspect\">");
    document.writeln("</object>");
    }
    The only one of the three tries above that plays the sound and advances to the video is the alert!
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,734
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Try a longer timeout period.

    Note than an alert() suspends program execution but setTimeout() does not - it just delays the execution of the function.
    Look into your code with that in mind.
    Last edited by Philip M; 01-16-2013 at 03:21 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,775
    Thanks
    55
    Thanked 519 Times in 516 Posts
    I'm not familiar with soundManager (I'm guessing it's a plug-in), but many audio players have event listeners built in. You could investigate the soundManager documentation, see if it has an "onuadioended" (or similar) event, and when that fires, call a function to run your video

    [EDIT]: If this is the same one you're using, the onfinish event at this link may prove useful:
    http://www.schillmania.com/projects/soundmanager2/doc/
    Last edited by xelawho; 01-16-2013 at 04:37 PM.

  • Users who have thanked xelawho for this post:

    tpeck (01-17-2013)

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,482
    Thanks
    0
    Thanked 635 Times in 625 Posts
    Note that document.writeln is as dead as Netscape 4 (the last browser that needed it) and since then alert has been repurposed as a debugging tool - so neither statement should appear in a live script.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    806
    Thanks
    42
    Thanked 6 Times in 5 Posts
    Thank you xelawho.

    It turned out to be 'onfinish' which worked.

    I have learnt to read the screed for the plugins, but I must confess, I would not have been likely to find that solution - even having read up on it.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #8
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    806
    Thanks
    42
    Thanked 6 Times in 5 Posts
    felgall, is there an alternative to document.writeln (besides document.write)?

    How else could you make the video play?
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Why so you need to use JS to create that <object>...</object> code? Why can't you just drop it in the HTML without using JS at all?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #10
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,482
    Thanks
    0
    Thanked 635 Times in 625 Posts
    Quote Originally Posted by tpeck View Post
    felgall, is there an alternative to document.writeln (besides document.write)?

    How else could you make the video play?
    using documentGetelementById and innerHTML works for all current browsers as well as older browsers such as IE5.

    Alternatively you could use the proper DOM commands such as createElement and insertChild to create and add HTML tags from JavaScript.

    Of course the simplest way where the tags are not being changed after the page loads is to simply hard code them in the HTML.

    write and writeln can only output to the page before it finishes loading so anything those commands can do can be done using HTML without JavaScript unless the values to be output are being generated (in which case a server side language would be more appropriate).
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #11
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    806
    Thanks
    42
    Thanked 6 Times in 5 Posts
    OP, I have to use the document.write method because an inline frame is being called and depending on a cookie (giving the disk drive letter), the video being played is either streamed across the web or played from a disk.

    However, I will investigate felgall's advice and see if I can get that working as an alternative. Not sure how that would work though...

    I've made a demo at:

    http://aapress.com.au/demo/diskorstream/page1.html
    Last edited by tpeck; 01-20-2013 at 07:57 AM.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)


  •  

    Posting Permissions

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