2

I'm looking to use multiple audio files in a tizen wearable web app. It works for 1 audio but no matter what i try it doesn't work for multiple.

I've tried declaring multiple audio files and then passing them as a variable to a function with no luck.

var sound1 = new Audio("audio/first_file.wav");
sound1.loop = false;
sound1.volume = 15.0;

var sound2 = new Audio("audio/second_file.wav");
sound2.loop = false;
sound2.volume = 15.0;

function startSample(sound) {
    sound.play();
    tizen.feedback.stop();
}

I've tried declaring the audio file within the function

var sound1 = "audio/first_file.wav";
var sound2 = "audio/second_file.wav";

function startSample(sound) {
    var soundSample = new Audio(sound);
    soundSample.loop = false;
    soundSample.volume = 15.0;
    sound.play();
    tizen.feedback.stop();
}

I even tried giving them separate functions, but it seems even with only one audio, declaring the audio variable within a function does not work.

function soundSample1() {
    var sound1 = new Audio("audio/first_file.wav");
    sound1.loop = false;
    sound1.volume = 15.0;
    sound.play();
    tizen.feedback.stop();
}

The one thing that does work is this, but only when there's only one audio file.

var sound1 = new Audio("audio/first_file.wav");
sound1.loop = false;
sound1.volume = 15.0;

function startSample() {
    sound1.play();
    tizen.feedback.stop();
}

Any help would be greatly appreciated.

Paul Clarke
  • 328
  • 2
  • 13

2 Answers2

1

After some further experimentation I ended up with this;

<audio id="myAudio">
    <source src="audio/first_file.wav" type="audio/wav">
</audio>
<audio id="myAudio2">
    <source src="audio/second_file.wav" type="audio/wav">
</audio>
<script>
    var sound1 = document.getElementById("myAudio");
    var sound2 = document.getElementById("myAudio2");
    function startSample(sound) {
        sound.play();
    }
</script>

Credit to w3schools for the original code which was modified from here https://www.w3schools.com/jsref/met_audio_play.asp

Paul Clarke
  • 328
  • 2
  • 13
0

This should work:

var sound1 = new Audio("audio/first_file.wav");
sound1.loop = false;
sound1.volume = 15.0;

var sound2 = new Audio("audio/second_file.wav");
sound2.loop = false;
sound2.volume = 15.0;

function startSample() {
    sound1.play();
    sound2.play();
    tizen.feedback.stop();
}
UkFLSUI
  • 5,509
  • 6
  • 32
  • 47
  • Thanks Rakibul, unfortunately still no go. As soon as there's two audios declared it won't work. AKA I can have either sound1 or sound2 declared but not both. I attacked it again tonight and managed to find a work around using HTML elements though. – Paul Clarke Oct 08 '19 at 10:26