...

View Full Version : sound array how do i newbie



pwesthead
07-23-2009, 04:40 PM
Hi i have a piece if javascript code which pulls random numbers from 1 to 90 and a piece of text so if number 1 is pulled it will show text kellys eye and so on. I have this working fine, but what i want to do now is play a mp3 file when a number 1 is pulled randomley it will play 1.mp3 and 80 will play 80.mp3and so on, i have downloaded soundmanger2 to play the files, but im not sure how to write the java code so the mp3 playes with the number pulled,

here is some of the code

function initialiseBingoPool() {
bingoPool = new Array;
for (var i = 0; i < 90; i++) {
bingoPool.push(i + 1);
}
easynet4u(bingoPool);
}
function initialiseBingoPhrase() {
bingoPhrase = new Array;
bingoPhrase[1] = "Kelly's eye";
bingoPhrase[2] = "One little duck";
bingoPhrase[3] = "Cup of tea";

and so on until 90


function callNewNumber() {

if (!(newNumber = bingoPool.pop())) {
window.location.href = 'delete.php?number=' + newNumber;
}


ajax_request();

// Update the current number display with the new number and phrase
document.getElementById("latestNumber").firstChild.data = newNumber;
document.getElementById("bingoPhrase").firstChild.data = bingoPhrase[newNumber];



setTimeout(callNewNumber,4000);


so how would i write some java code to play mp3 as well as the bingo numbers and bingo phrase


im using soundmanager2 to play the mp3 just need some help with the coding

thanks paul

Fou-Lu
07-23-2009, 05:35 PM
Despite the sound of their names, java and javascript are entirely different languages.
Moving from Java to Javascript forum.

Philip M
07-23-2009, 05:48 PM
See:- http://webdesign.about.com/od/sound/a/play_sound_oncl.htm



<span id="dummy"></span>


// Update the current number display with the new number and phrase
document.getElementById("latestNumber").firstChild.data = newNumber;
document.getElementById("bingoPhrase").firstChild.data = bingoPhrase[newNumber];

var soundfile = URL to soundfile; // e.g. newNumber.mp3
document.getElementById("dummy").innerHTML=
"<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";



Brevior saltare cum deformibus mulieribus est vita - Life is too short to dance with ugly women

pwesthead
07-25-2009, 04:15 PM
Hi i have tried the code from philip b but still can't get sound to play
here is the code i have so far


function initialiseBingoPool() {
bingoPool = new Array;
for (var i = 0; i < 90; i++) {
bingoPool.push(i + 1);
}
easynet4u(bingoPool);
}
function initialiseBingoPhrase() {
bingoPhrase = new Array;
bingoPhrase[1] = "Kelly's eye";
bingoPhrase[2] = "One little duck";
bingoPhrase[3] = "Cup of tea";

the code above pulls number from random and also plays the text, but i need it to play mp3 files aswell i have tried everything but still no joy here is the code im using for the soundfiles.


soundManager.onload = function() {
playNextSound();
}

var soundfile = ['number/]; // for example
var urlCounter = 0; // and keep track of the current sound..
function playNextSound() {
if (urlCounter < soundfile.length) {
var s = soundManager.createSound({
id:'test'+urlCounter,
url: soundfile[urlCounter]
});
s.play({
onfinish:function() {
playNextSound();
}
});
urlCounter++;
}
document.getElementById("latestNumber").firstChild.data = newNumber;
document.getElementById("bingoPhrase").firstChild.data = bingoPhrase[newNumber];
document.getElementById("test").innerHTML="<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";



if i use var soundfile = ['number/1.mp3','number/2.mp3', 'number/3.mp3']; // for example, this works but only playes 1.mp3 then 2.mp3 and so on, but at least sound is being played,How do i write the code so the mp3 files play with a number and phrase is called please help
thanks paul

pwesthead
07-26-2009, 01:48 PM
anyone!!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum