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.
Related
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.
I'm new to JavaScript, so my problem will probably be very easy to fix for someone with any experience. I'm making a music blog with a few friends, and I am trying to make my own custom music player using jPlayer.
I want a simple JavaScript function that you supply the title of the song and the mp3, and it adds itself to the jPlayer playlist. This is the JavaScript function that I have...
function add_song(title, mp3)
{
myPlaylist.add({
title:"Tempered Song",
mp3:"http://www.jplayer.org/audio/mp3/Miaow-01-Tempered-song.mp3"
});
}
I want to be able to call the function anywhere in my body, using this code...
<script>
add_song("Your Face", "http://www.jplayer.org/audio/mp3/TSP-05-Your_face.mp3");
</script>
This, however, doesn't actually add the song. I'm guessing that this has something to do with having to set up the jPlayerPlaylist in the $(document).ready() function. I'm guessing that my variable "myPlaylist" isn't correctly initialized when I try to call add_song(). Like I said, I'm new to JavaScript so try to make it simple for me.
You can check out the code I have at my website to better guide me in my problem. Thanks!
The problem is indeed that you're setting up your jPlayerPlaylist after you're calling add_song. The browsers blocks and runs the Javascript code in <script> tags as soon as it encounters them, which is before document.onload and jQuery equivalents are fired.
What exactly are you trying to accomplish? Do you really want to load up some hardcoded playlist elements right as the page is loading, or do you actually want to attach these to buttons or links? For the former, move the function calls to the onload function, and for the latter, make new event handler functions and attach them to the appropriate elements.
If you're really just going to supply the function manually in the address bar or something, it should work fine. It simply won't work before the page has loaded.
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
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.
Could someone help me create some javascript to perform the following behavior. Upon the entering of Konami Code while at a website (see:: http://files.www.gethifi.com/posts/konami/index.html for example), I want an mp3 to start playing in the background. I want to do this without any external library, such as jQuery.
Thanks in advance for your help!
You can start with the onKeyUp event, which gives you access to the keyCode property. You need a way to keep track of the keys pressed and you need to check each time to see if they match up to the Konami Code.
To play an MP3, take a look at the object tag and also see if you can add it to the DOM programmatically. Using all this information, it should be trivial for you to figure out how to write it all together.