Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript play audio from buffer

function playAudio(buffer) {
    var source = context.createBufferSource();
    source.buffer = buffer;
    source.connect(context.destination);
    source.start(0);
    }

    // Load and decode audio file
    function loadSound(url) {
    var request = new XMLHttpRequest();
    request.open('GET', url, true);
    request.responseType = 'arraybuffer';
    request.onload = function() {
        context.decodeAudioData(request.response, function(buffer) {
            playAudio(buffer);
        });
    }
    request.send();
    }

    // Next button
    $("#next").click(function(){
        var next = $("#next").attr("data-next");
        if(next != ""){
            loadSound(next);
        }
    
    });

    // Previous button
    $("#previous").click(function(){
        var previous = $("#previous").attr("data-previous");
        if(previous != ""){
            loadSound(previous);
        }
    
    }
    );

    // Play button
    $("#play").click(function(){
        var play = $("#play").attr("data-play");
        if(play != ""){
            loadSound(play);
        }
    
    }

    // Pause button
    $("#pause").click(function(){
        var pause = $("#pause").attr("data-pause");
        if(pause != ""){
            loadSound(pause);
        }
    
    }

    // Stop button
    $("#stop").click(function(){
        var stop = $("#stop").attr("data-stop");
        if(stop != ""){
            loadSound(stop);
        }
    
    }
    
    // Volume up button
    $("#volume-up").click(function(){
        var volumeUp = $("#volume-up").attr("data-volume-up");
        if(volumeUp != ""){
            loadSound(volumeUp);
        }
    
    }

    // Volume down button
    $("#volume-down").click(function(){
        var volumeDown = $("#volume-down").attr("data-volume-down");
        if(volumeDown != ""){
            loadSound(volumeDown);
        }
    
    }

    // Volume mute button
    $("#volume-mute").click(function(){
        var volumeMute = $("#volume-mute").attr("data-volume-mute");
        if(volumeMute != ""){
            loadSound(volumeMute);
        }
    
    }

    // Volume unmute button
    $("#volume-unmute").click(function(){
        var volumeUnmute = $("#volume-unmute").attr("data-volume-unmute");
        if(volumeUnmute != ""){
            loadSound(volumeUnmute);
        }
    
    }

    // Themes button
    $("#themes").click(function(){
        var themes = $("#themes").attr("data-themes");
        if(themes != ""){
            loadSound(themes);
        }
    
    }
Comment

PREVIOUS NEXT
Code Example
Javascript :: same click event in multiple elements in on event 
Javascript :: how to see if checkbox is checked 
Javascript :: express js delete request 
Javascript :: textbox in javascript 
Javascript :: pass variable to partial view ejs 
Javascript :: text filed press enter event jquery 
Javascript :: unshift method in javascript 
Javascript :: how to replace empty string with undefined 
Javascript :: javascript exponential 
Javascript :: moment localization 
Javascript :: javascript style inline react 
Javascript :: onsubmit in js 
Javascript :: get data from url using react 
Javascript :: convert a string to array in javascript 
Javascript :: await is only valid in async function 
Javascript :: setinterval javascript 
Javascript :: video mute and unmute 
Javascript :: javaScript getHours() Method 
Javascript :: javascript fetch request GET 
Javascript :: javascript get width 
Javascript :: react youtube npm 
Javascript :: js comparison operators 
Javascript :: javascript Strict Mode in Function 
Javascript :: react usecallback 
Javascript :: gitignore subfolders 
Javascript :: react native create text file 
Javascript :: js date get hours 
Javascript :: every break js 
Javascript :: async function syntax 
Javascript :: password validation with regular expression in javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =