Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-10-2012, 03:00 PM   PM User | #1
jerrell
New Coder

 
Join Date: Nov 2011
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
jerrell is an unknown quantity at this point
Help with audio play and pause using jQuery.

Hello,

I am attempting to "play" and "pause" music on my page when the #startbutton is clicked ... I also have a volume button #volume that I want to use to turn the music off and on. I am using jQuery to make this possible, below is the jQuery code.

I can also provide the HTML if need. Thank you in advance for ALL your help.


Code:
 

$(function() {

    //
 	var $volume = $( '#startbutton' );
    var $fsound =  $('#fsound');
    $fsound.hide();
    buzz.defaults.formats = [ 'ogg', 'mp3' ];
    

	//
	var s = null,
	
	AnimationSpace = {
		settings: {
			startButton: $("#startbutton");

		},
		
		init: function() {
			s = this.settings;
			this.startAnimation();
		},
		
		startAnimation: function () {
			s = this.settings;
			
			s.startButton.click(function() {
				$("div.target").toggleClass("animate");
				if (s.startButton.attr("value") === "ANIMATE THE SCENE") {
					s.startButton.attr("value", "RESET THE ANIMATION");				
				} else {
					s.startButton.attr("value", "ANIMATE THE SCENE");	
				}
				
				//
			var Sound = new buzz.sound( 'audio/birthday' );
				if ( !buzz.isSupported() ) {
      				$volume.hide();
        			$fsound.visible();   
    			}else{
    				Sound.loop().play().fadeIn( 5000 );
				}
	
   			 $volume.click( function() {
        		if ( $( this ).hasClass( 'all' ) ) {
             		Sound.mute();
             $( this ).removeClass( 'all' ).addClass( 'none' );
        		} else if ( $( this ).hasClass( 'none' ) ) {
           			Sound.unmute();
             $( this ).removeClass( 'none' ).addClass( 'all' );
       			}
        		return false;
    		});	
				//
				
				
			});
		}

	};

	AnimationSpace.init();
});
jerrell is offline   Reply With Quote
Old 05-10-2012, 09:16 PM   PM User | #2
jerrell
New Coder

 
Join Date: Nov 2011
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
jerrell is an unknown quantity at this point
Solution to the problem

I was able to put together a solution for the problem I was having... still a few bugs but in case anyone else runs into this problem. Here is the working code (with minor bugs).


Code:
$( function() {
    var $volume = $( '#volume' );
    var $start = $('#startbutton');
       
    buzz.defaults.formats = [ 'ogg', 'mp3' ];

    var Sound = new buzz.sound( 'audio/birthday' );
        
$start.click(function(){
    if ( !buzz.isSupported() ) {
                   
    }else{
    
    Sound.play().fadeIn( 5000 );
	}
    });
    // Volume button

    $volume.click( function() {
        if ( $( this ).hasClass( 'all' ) ) {
             Sound.mute();
         
            $( this ).removeClass( 'all' ).addClass( 'none' );
        } else if ( $( this ).hasClass( 'none' ) ) {
           
            Sound.unmute();
        
            $( this ).removeClass( 'none' ).addClass( 'all' );
        }
        return false;
    });

});
jerrell is offline   Reply With Quote
Reply

Bookmarks

Tags
audio, html5, jquery, sound

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:22 AM.


Advertisement
Log in to turn off these ads.