Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    sound array how do i newbie

    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
    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

    Code:
    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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Despite the sound of their names, java and javascript are entirely different languages.
    Moving from Java to Javascript forum.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,150
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    See:- http://webdesign.about.com/od/sound/...sound_oncl.htm


    Code:
    <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
    Last edited by Philip M; 07-23-2009 at 05:57 PM.

  • #4
    New Coder
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

    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";
    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.

    Code:
    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
    Last edited by pwesthead; 07-25-2009 at 04:17 PM. Reason: wrong code

  • #5
    New Coder
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    anyone!!!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •