CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   alert as a time delay (http://www.codingforums.com/showthread.php?t=285878)

tpeck 01-16-2013 12:39 PM

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?

Philip M 01-16-2013 01:03 PM

Quote:

Originally Posted by tpeck (Post 1306616)
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.

tpeck 01-16-2013 01:27 PM

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!

Philip M 01-16-2013 02:56 PM

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.

xelawho 01-16-2013 04:35 PM

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/

felgall 01-16-2013 06:19 PM

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.

tpeck 01-17-2013 08:28 AM

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.

tpeck 01-17-2013 08:30 AM

felgall, is there an alternative to document.writeln (besides document.write)?

How else could you make the video play?

Old Pedant 01-17-2013 11:43 PM

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?

felgall 01-18-2013 01:10 AM

Quote:

Originally Posted by tpeck (Post 1306837)
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).

tpeck 01-20-2013 07:47 AM

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


All times are GMT +1. The time now is 03:04 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.