I'd really love to know how to make a div play sound in an onclick event for the computer and other devices. And if there is a way to change an already existing piano script to work on other devices
The already existing code: jsfiddle.net/Nf68y
You can use a jQuery library like jPlayer for cross browser/device audio playback: http://jplayer.org/
But you might also just want to look in the html5 audio element, to see what that is all about :)
Related
I am looking for a working way to play sound in facebook HTML5 games.
HTML5 audio is pretty buggy right now and has too many problems to use it in my game.
I tried a sound kit : SoundManager2 which uses flash (http://www.schillmania.com/projects/soundmanager2/) but it is not working inside facebook because of iframes...
Is there any way to have properly working sounds on an HTML5 game ? Or if anyone knows a way to make soundmanager work inside facebook
edited to remove details that should be removed
I would like to play short sounds in my new JavaScript game.
It is a poker game so the sounds are pretty short (dealt card sound, shuffle deck sound, your turn beep etc.)
I Googled before posting here but all I could see was some MP3 players that actually have "play\stop" buttons, (which are not good for me)
Any ideas?
Put an <audio> element on your page.
Get your audio element and call the play() method:
document.getElementById('yourAudioTag').play();
Check out this example: http://www.storiesinflight.com/html5/audio.html
This site uncovers some of the other cool things you can do such as load(), pause(), and a few other properties of the audio element.
When exactly you want to play this audio element is up to you. Read the text of the button and compare it to "no" if you like.
Alternatively
http://www.schillmania.com/projects/soundmanager2/
SoundManager 2 provides a easy to use API that allows sound to be played in any modern browser, including IE 6+. If the browser doesn't support HTML5, then it gets help from flash. If you want stricly HTML5 and no flash, there's a setting for that, preferFlash=false
It supports 100% Flash-free audio on iPad, iPhone (iOS4) and other HTML5-enabled devices + browsers
Use is as simple as:
<script src="soundmanager2.js"></script>
<script>
// where to find flash SWFs, if needed...
soundManager.url = '/path/to/swf-files/';
soundManager.onready(function() {
soundManager.createSound({
id: 'mySound',
url: '/path/to/an.mp3'
});
// ...and play it
soundManager.play('mySound');
});
Here's a demo of it in action: http://www.schillmania.com/projects/soundmanager2/demo/christmas-lights/
One Word. SoundManager2
I believe the common way is to make an invisible flash applet (as "sound library") and trigger it to play the sounds appropriately.
Is there any way how to play audio for the game slot machine when the reels spinning using javascript.
I tried using , and tags.. The music is playing but on some of the versions there is no sync..
The process is:
- Once the spin button is pressed.. I am showing the animated reels images and embeding the music file with tags.
May be is there any better solution to load music file before and play using .play() function in javascript. I tried this but not working on someversions of firefox and other browsers.
One solution some use is multiple instances of jPlayer (one per channel). You can then preload the sounds and .play() them at will.
jPlayer will try to do HTML5 and use Flash as a backup solution.
http://jplayer.org/
I wanted to implement something with JQuery (trying to avoid external plugins), that will play sound on clicking "play" and stop the sound by clicking "stop", and will also work cross-browser (including iPhone and iPad devices, so no flash).
Is there a solution to this?
I have only ever found external plugins..
Unfortunately no. For years the only way to play audio in the browser has always required a plugin. More recently, the HTML5 standard has provided a cross-browser standard for playing audio. Unfortunately many browsers still don't implement HTML5, so this doesn't really fix your problem either.
I did a lot of searching for what I thought would be a pretty common question, but I came up with nothing. If there is another thread with a similar topic, please let me know.
Basically, I'm looking for a way to have an .mp3 file play in a website without relying on a flash-based player. I've searched w3 schools and every forum I can think of, but every media player I've found so far has been some sort of proprietary flash player.
Doesn't HTML support some sort of native player? I've found some that rely on Windows Media Player which is close, but I want the player to work on an iPhone and something tells me WMP won't get that done...
PS, as I'm thinking more about this this idea just popped into my head: a javascipt player and inside the <noscript> tag, put a flash player? I'm running a music blog (# http://www.freshoncampus.com) so the less code per post, the better...
Yes you can, with HTML 5.
This is a pretty good explanation of how you might go about doing this.
The caveat is that HTML5 support is not universal, but iOS devices (iphone) have a good start with supporting HTML5.
Edited to add:
From the question, it's hard to discern if you're looking for a way to play multiple mp3's with a nice gui interface, or just use audio as a background.
For the former, you will need to use Javascript to handle controls, and loading of the src element (I'd search for custom built javascript or jquery plugins to handle this).
For the latter, my solution above will work.
Also, background music in a webpage is highly annoying to most users, so caveat emptor.
You could go with something like http://www.schillmania.com/projects/soundmanager2/
which should autodetect the best option to play the sound.
jplayer? Not sure about MP3/OGG thing though...
First, HTML5's “audio” tag.
Second, you can use “embed” tag — it will play with whatever browser plugin is installed (not just WMP).
Not sure what would work in iPhone, though.
(and I might be wrong about exact tag names)