Unable to play a local audio file

Unable to play a local audio file

BY 28 May 2017 Web Application Development

Hello,

I am developing a web app for the Gear S3 (wearable-3.0) and I need to play an audio local file. I don’t know anything about how to do this so I search it on internet and I fould a good guide of Tizen for this (https://developer.tizen.org/ko/community/tip-tech/working-web-audio-api?langredirect=1). However, XMLHttpRequest is used in that guide and for an odd reason, it does not work. So I thought I could use a FileReader Objetc with the method readAsArrayBuffer, but it still doesn’t work.

This is the js code:

var context = new webkitAudioContext();
    file = new File([“”],’../sound/mountain.mp3′);
    
    reader = new FileReader();
    reader.onload = function() {
        arrayBuffer = reader.result;
        alert(arrayBuffer.length);
        context.decodeAudioData(arrayBuffer, function onSuccess(buffer){
            if (!buffer){
                alert(“Error decoding file data.”)
                return;
            }
            reader.readAsArrayBuffer(file);
            source = context.createBufferSource();
            source.buffer = buffer;
            source.connect(context.destination);
            source.start(0);
        }, function onerror(error){
            alert(“Error at decodeAudioData.”);
        });
    };

————————————————-

As you can see, the audio file is located in (relative path) ../sound/mountain.mp3

Does anyone know how to do this? Thank you for your input.

Written by