Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am creating a craps game using javascript. I have pretty much everything working the way its supposed to be, just have to make a few minor adjustments, but the part I am stuck on is creating some type of type function, or possibly using the setTimeout(). I have a .wav file playing the sound of dice being rolled, but what I would like to do is have the text if the user won or lost appear after the sound of the dice being rolled(after the .wav file stops playing the dice rolling sound).
I don't think you can detect any event about the sound file ending.
You should play the sound, then start a setTimeout function with a hard-coded duration.
Eg:
setTimeout(diceRolled,3000); //these are millisecond -> 3 seconds wait
// ..........
function diceRolled(){
//do anything here
}
I would say the "correct" answer is to use html5 audio and bind to its various events - you can get the file's duration, detect if a sound has finished playing, get its current playback location, etc.
However, it's fairly complicated to use, and I wouldn't recommend it for this purpose or for starting javascripters.
http://html5doctor.com/html5-audio-the-state-of-play/
http://www.html5rocks.com/en/tutorials/webaudio/intro/
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have created a JavaScript program that is intended to run on multiple computers at once.
I need to know how to run a function on all of the computers at the same time.
I have tried making a function that uses setTimeout to basically wait until a certain time. I have done multiple checks on both computers and it seems to think that it is making up for setTimeout's delay, but it is still off by around 0.4 seconds.
You can synchronize your applications either using a central server with Websockets, for example. Or, if you want to use something really fancy, you can use WebRTC signalling. It is a bit harder to get into, but it works brilliantly.
Update: I just read that you want to use it for a Rubik's cube competition? With WebRTC, you can even integrate a live video connection between both players so that they can see their opponents cube. Sounds fun!
There is no way to 100% guarantee that the function will run at the same time on both the computers. Even with Websockets there will be a network delay to reach each computer and you cannot guarantee network message will reach to all computers at the same time.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I would like to write a program that "arranges" multiple audio buffers. Similar to a DAW, I want to "layer" audio tracks on top of each other at custom timestamps. Is this even possible, and if so, how would I implement it?
I apologize in advance for this extremely general question, but I couldn't find any good resources on this topic. Thanks for the help!
Yes, this is possible.
First, load your audio data into AudioBuffer instances.
Next, you want to create an AudioContext, which is basically the root of a graph of connected nodes where your audio flows about.
Now, create an AudioBufferSourceNode for each AudioBuffer and connect it to the audio context's destinationNode. This basically plugs a buffer player directly to the output.
From there, you can call .start() on your AudioBufferSourceNode instances to play them back immediately, or schedule them to play at some point in the future.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I found out that it's possible to create audio buffers with Javascript (https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createBuffer). I'm still not sure what this API does, but I'd like to know whether there is there a way to add x seconds of silence in front of an .ogg file and play it in the browser?
Edit:
The purpose is to create a timer that works on mobile browsers even for long timeouts. If the phone goes to sleep SetTimeout and SetInterval will stop (as well as other JavaScript code). My workaround would be to create a sound file which contains i.e. 40min of silence and then plays the alarm bell (the sound keeps playing in the background even though JavaScript is not executing anymore in background tabs). But creating such files is not very flexible and costs traffic. I thought of using this API to accomplish what I've described without creating a file with silence + bell offline.
Maybe this also solves your problem. I archived this behavior in another way. I just waited x seconds before playing the sound.
My Code looks like
var audio = new Audio('sound.mp3');
function start() {
audio.play();
}
setTimeout(start, 2000);
Instead of 2000 you can use x and multiply it with 1000.
Does it work for you or is there a point that I'm missing?
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
If you're not familiar with the concept of a Microgame, check out this video of WarioWare Twisted.
I'm interested in setting up a site where users can play series of browser-based Microgames which are delivered to them by a server. Ideally this would allow me to crowdsource the games and have an open submission system. What sort of scheme could I use to make this work?
I'm thinking that one way to do it would be to have each game consist of:
A javascript file that defines a MicroGame object that controls a rectangular portion of the screen, gets input and timing information from the main page, then calls back to the main page with a "Success" or "Failure" message.
A folder of assets that must be downloaded before the game executes.
Is this possible to do, client-side within a browser? Where would be a good place to start figuring this out?
There are a lot of open issues here. The biggest problem is what language do they submit games in which you can execute safely on the players machines? That said, there are tools like this out there. You could look at the excellent Play My Code for inspiration.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
So I am on the 11th level of my game (plan to have 20-25) and listening to the music that is going to be on the game, over and over, to see if it fits while testing it.
Now I've decided it is time to start working on the media player for it.
I plan to have all the songs on a loop. You can skip songs or go previous and play/pause. There also will be a button to mute.
I know how to add the GUI to the screen and use the mouse clicks to trigger methods. Just wondering what is the most used way instead of building it from nothing and wasting time.
I am just wondering if there a tut/guide as I plan on pulling an all-nighter to do this.
I'm in college but it's summer so decided this would be great for my portfolio.
Here's a demo vid of it. It is my first game so go easy! :)
Use the <audio> tag. It has functions such as .play() and .pause(). To switch tracks, you'd modify the src to point to a different audio file, much in the same way you'd switch the src of an <img> tag to display a different image.
EDIT: I just watched video and I want to play this thing. The twist on the normal platformer (all the platforms being ones that you slowly fall through) could either be really awesome or really frustrating. I'm leaning towards awesome but that remains to be seen!