user2759665
user2759665

Reputation:

Change firefox playback bar into a onclick button for audio

SAME ISSUE! As we all know firefox and audio is a problem because of patents and such. I found this little code on the internet to play my sounfile.

I would like to play multiple files instead of just one while having the display bar not show up in the browser

Please note. Do not give me codes that have no compatibility outside chrome and ie.

HTML

    <audio id="audioplayer" preload controls loop style="width:400px;">
    <source src="sounds/sound1.mp3">
    <source src="sounds/sound1.caf">
    </audio>

Javascript

    <script type="text/javascript">
    var audioTag = document.createElement('audio');
    if (!(!!(audioTag.canPlayType) && ("no" != audioTag.canPlayType("audio/mpeg")) &&  ("" !=     audioTag.canPlayType("audio/mpeg")))) {
    AudioPlayer.embed("audioplayer", {soundFile: "sounds/sound1.mp3"});
    }
    </script>

RECAP: Have the sound play on a button or link click. Have multiple sounds available to play (not just one) Compatibility with firefox non visible soundbar.

Upvotes: 0

Views: 69

Answers (1)

Pietertje
Pietertje

Reputation: 43

Still learning myself. But this is a button, with a script to play an audio file. (part of my own solution) Plays only 1 sound at a time, but doesn't show anything about it. You could also make a funtion like this, without setting the src, using the pause() command. currenttime is used to change the part where the audio file was.

<a href="#" onclick="playSnd('sounds/close_chat.wav');">Sound play button</a><br>

<script>

sound = new Audio();

function playSnd(soundSrc) {
sound.src = soundSrc;
sound.play();
}
</script>

Upvotes: 0

Related Questions