Play a 2nd flash video after the first ends - javascript

I have a flash object set up in the standard format:
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
swfobject.embedSWF("swfplayer.swf", "myContent", "300", "120", "9", "expressInstall.swf");
</script>
but I want to start playing a second flash video on a different part of the web page the moment the first video ends. Is there a kind of listener of some sort to use?
Thanks

There actually is a way to do this, providing you movie is more or less timeline based. There's a couple calls that you can make to the flash object through javascript that will return you values you can check against to determine if the movie is complete.
To retrieve the current frame of the movie use:
document.getElementById("myFlashObject").TCurrentFrame("_root");
To check if the movie is playing use:
document.getElementById("myFlashObject").IsPlaying()
If the movie is stopped on a frame using the "stop()" method, this will return false. There's quite a few other methods you can use as well that you might find useful in playing the other movie. Here's a link to the Adobe reference docs:
http://www.adobe.com/support/flash/publishexport/scriptingwithflash/scriptingwithflash_03.html
Note: I tested this and it works with the flash player 10 in firefox. You may want to double check the cross-browser compatibility of these methods.

You could approach it from these two possibilities: LocalConnection or ExternalInterface.
I would go with ExternalInterface personally. With it, you can set up a javascript function that receives a call from videoPlayer_1 when its video has ended. To this javascript function you could pass an ID to determine which player has finished, and then send a call back up to the appropriate next player to tell it to start playing. You could repeat this process as many times as you have/swf's with videos.
I would have included an example but you didn't mention as2 or 3.
As for LocalConnection, you could create a group of movies with a local data connection, but this is easily broken by certain scenarios of multiple browsers/swfs, so probably not the most reliable method. However if you wanted to give it a shot, look up Grant Skinner's SwfBridge class to make things much easier.

Look at Detecting end of Flash movie in javascript

Related

How to detect the end of an embed flash movie

I have been struggling with this problem for a some time.
Basically have no clue how to do this.
I have a simple website where I have embeded a flash movie from a different site.
I need to detect when this movie reaches its end and then do some action ...
Is this possible via jquery/js?
Thank you.
s_
Basically there is a flash class called flash.external.ExternalInterface
AFAIK you can use that one to interface with JavaScript.
Please have a look into the details how to use it.
To get notified when a embedded flash video reaches the end I put a one-line command into the last frame on the time line:
dispatchEvent(new Event("VideoFinished"));
and hook up to the movie with
myMovie.addEventListener("VideoFinished", myMovieFinished);
where myMovieFinished is the function to call. There you could place the call to utilise the ExternalInterface.

Add effects to already recorded sound with Web Audio API

My task is to add some effect to the recorded file.
Here is a script in action I'm using
Recorder.JS
and here is a code https://github.com/cwilso/AudioRecorder/blob/master/js/recorderjs/recorder.js
I want to add pitch.
I tried looking in other codes which add some effects to the audio.
But it seems like recorder.js handles buffers differently.
edit
function playbackRecorderAudio() {
audioRecorder.getBuffer(function(buffers) {
var source = audioContext.createBufferSource();
source.buffer = audioContext.createBuffer(1, buffers[0].length, 44100);
source.buffer.getChannelData(0).set(buffers[0]);
source.buffer.getChannelData(0).set(buffers[1]);
source.connect(audioContext.destination);
source.noteOn(0);
});
}
here is how my code looks now, with this function, I request already recorded audio and play it back.
Can I simulate some effect to get close to this: http://www.youtube.com/watch?v=Lr80slqJ3zo
This is in Georgian but I hope you get the idea. Its more like Helium Pitch. (note, I don't whant to change audio speed).
When I tried to research helium effect I found this: http://chemistry.about.com/b/2013/08/26/helium-voice-is-not-higher-in-pitch.htm
it saies that sound should be 2.5 faster then air.
Can I get something close to this?
edit
from what #cwilso suggested, http://chromium.googlecode.com/svn/trunk/samples/audio/granular.html is the closest I have seen so far. But I could not manage to modify it, to work with my playbackRecorderAudio().
Thats why I'm starting a bounty with everything I have
edit
here is a jsFiddle of my code:
http://jsfiddle.net/Lsvnp/1/
First let me describe what I'm trying to achieve:
I want to record sound from users microphone, add this effect to it.
When user press "stop recording" button (stopRecording function) , it will prepend HTML audio which will allow user to listen what he has recorded. If he likes it, he then will upload it to my server (uploadAudio function)
WHen page is loaded, recording is not initalized. to initialize recording, user has to press some button which will trigger recordAudio function.
Now the problem is that I don't know where to connect my playbackRecorderAudio function. to use it as coverter from buffer.
The code of the granular effect you want is usable. The only thing you need to do is connect the output from your source node to the first node of the granular effects page code. Still that code is a bit messy but I will try to explain it as good as possible beneath.
After some searching in the code, it looks like the audio structure goes like this:
source -┬-> grainWindowNode -┬-> panner -┬-> dryGain -> compressor -┬-> destination
└-> bypass -┘ └-> wetGain -> convolver -┘
I made the code so it works for you, see this jsfiddle
This is a bit hard to make as you need to set all the values yourself to fit what you want.
All the code is in the jsfiddle, and there are two things you have to do to make it work:
read the comment on top (download that file and put it on the same server as where you are hosting it, else CORS makes sure you can't fetch the resource. (or you must specify a header on the server)
Put this code somewhere in your code, so that the function playbackRecorderAudio() does something useful. I can help you if you provide me all your code, to make sure it works.
If you want any explainment about the code feel free to ask (I do not know your current knowledge about the audio api, and to explain everything?)
You should probably look at using OfflineAudioContext rather than Recorder.JS - OAC can work in faster-than-realtime.
That said - "helium pitch" looks pretty hard to do, as it alters the harmonics of your voice. That sounds more like vocoding, with the voice sound being the modulator and the carrier, but shifting the harmonic bands (or something like that). The YouTube video you pointed to sounded like it was actually pitch-shifted, but with rate correction - like granular synthesis. Check out Chris Rogers' example http://chromium.googlecode.com/svn/trunk/samples/audio/granular.html - set the speed to 1.0, and the pitch to something greater than zero (several hundred cents, at least). Is this the effect you're looking for? If you, you can dig in to Chris' example to see how to do that, or use a live-effect version like the "pitch doubler" in my input effects (http://webaudiodemos.appspot.com/input/) (which can actually be set to be faster or slower, and controlled to be something other than octaves).
Pitch shifting is achieved using FFT (Fast Fourier Transform) which is implemented in the Web Audio API. O'Reilly has a book "Web Audio API" which covers the API nicely. You can see the chapter on Pitch and the Frequency Domain here.

Create an event that starts if the page makes any sound?

I need to create an event that starts if the page is making any sound, or if there is a file playing on it.
Is there a way to do this?
Thanks
There are multiple way for your page to play a sound -- mostly via <object>, <embed> (though you can do it in an <applet> too!). Trouble is each one of these embeds a plugin in the page and each plugin has different parameters, and they are specific for each provider. And there is a multitude of them... And sound formats... so you could write a script that iterates through all these tags and finds all the parameters for them and try to figure out if this is a QuickTime plugin, or a real player, or windows media etc etc etc -- point being it will be a horrible function and it will still not cover all the cases. So I guess NO should be the short answer.
Only possible with HTML5 supporting browsers, but if you use the <audio> tag you have an event attibute at your disposal called onplay
If jQuery, you can do an each event bind for the play event for all audio tags on a page.
Try it:
http://jsfiddle.net/jdgiotta/rvpBj/

simple javascript to replace 1 movie with another

I'm aware this is probably a very simple problem with a 1-line-of-code answer but I've been on it a while now and it's still eluding me. We have a site that comprises mainly of an embeded flash object containing navigation controls. All I want is to insert a small .swf movie that will play like an intro scene to the website before the main .swf loads for the site itself. All this means is I want to call up 1 flash object, play it through and then replace it with another once finished. This seems to be a relatively simple desire but after a couple of hours worth of forum-trawling I'm still denied a simple solution. Anyone know any better?
The simpler solution is for all of this to be handled within Flash. That would give you a finer overall control.
If you handled this both with Javascript & Flash, a likely problem will be to have to wait for a movie to be loaded before it starts playing.
You could for instance call a Javascript function from the first movie when it completes playing, but you won't be able to avoid the delay between the two movie whilst the second movie loads.
If for some reasons, you don't have access to the code in any of these movies, create a third movie that will act as a container for both swfs where you'll be able to monitor loading progress and react accordingly.
As far as I know (will be glad if someone will correct me) you can't really know when Flash object has finished loading - for the JavaScript code it's pretty much "black box".
So, your best alternative is hide the "intro" after specific amount of time, for example five seconds:
window.setTimeout("document.getElementById('intro').style.display = 'none';", 5000);
This will hide element with the ID "intro" after five seconds.
There are a couple of solutions.
You can embed the intro and the navigation in one movie clip and just show the navigation after the intro movie has played.
You can also use ExternalInterface in flash in the intro movie. ExternalInterface allows Flash to call JavaScript functions and vice versa. So you basiclly write a small function in JS that changes the clips and call it via ExternalInterface at the end of the intro.

javascript flashvar question with JW Player

I don't know if I'll be able to get this answer here, but I'm trying to get the JW Player to toggle between high and low quality settings. Here is my code:
<script type="text/javascript">
var so = new SWFObject('/lessons/videos/player.swf','mpl','610','480','9');
so.addParam('allowfullscreen','true');
so.addParam('allowscriptaccess','always');
so.addVariable('plugins', 'http://www.mbira.me/lessons/videos/plugins/hd/hd.swf');
so.addVariable('hd.state',false);
so.addVariable('hd.autoswitch',false);
so.addVariable('hd.bandwidth',3200);
so.addVariable('hd.file', '/lessons/videos/Buka_Tiende_from_calculator.flv');
so.addVariable('file','/lessons/L2/Nhemamusasa_Acoustic.flv');
so.write('mediaspace');
</script>
I read here that there is a setting that there is a default built into the HD plugin to switch determined on the users bandwidth. I downloaded a patch here:
http://interfacelab.com/patch-for-hd-plugin-for-jw-player/
So I could disable that behavior to test, but still no luck. You can see in my code, that for now, I just have two different videos to toggle in order to test if things are working. I should say that both those videos are actually "high quality" for now, but that shouldn't make a difference I guess. Any ideas, and if not, any other places I could look to implement this functionality?
Thanks!
Joel
so.addVariable('plugins', 'plugins=hd-1');
needs to be changed to:
so.addVariable('plugins', 'hd-1');
The example page was incorrect...

Categories