Languages

Menu
Sites
Language
Unable to play a local audio file

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.

Responses

2 Replies
André Reus

hi 

I used 2.3.2 for Gear S3. I am not sure about Tizen 3.0 support for Gear S3 till now. 

btw, try like this

<div class="ui-page ui-page-active" id="main">
        <header class="ui-header">
		<h2 class="ui-title">Audio Player</h2>
	</header>
	<div class="ui-content content-padding">
		<audio data-controls="true" style="width:100%;" controls>
			<source src="Color_short_version.mp3" type="audio/mpeg" />
			<p>Your browser does not support the audio tag.</p>
		</audio>
	</div>
</div>

Project structure

Output:

Let me know the result please. 

Frank

Hi André,

You are right. It works! Thank you very much.

Best regards,

Luis Francisco.