djquinn
djquinn

Reputation: 23

javascript force play sound instead of download

I recently made a soundboard about hearthstone, but when I click on the card(image) on my localhost it plays the sound(like intended), while when I click on the card(image) on my online hosting it downloads the file.

Is there a way to make sure it always plays the sound?

<script type="text/javascript">
    $(document).ready( function() {
        $('.card').click(function(){
            $('#wrap').html('<embed id="embed_player" src="'+$(this).attr('name')+'" autostart="true" hidden="true"></embed>');
        });
    });
</script>
<div id="pictures">     
    <img name="media/Sir-finly.mp3" src="media/Sir finly.gif" class="card"       id="sir-finly" alt="" />
    <img name="media/ShifterZerus.mp3" src="media/ShifterZerus.gif"    class="card" id="shifterzerus" alt="" />
    <div id="wrap"></div>
</div>

hope you guys can help me.

Upvotes: 2

Views: 1439

Answers (1)

Rodion Golovushkin
Rodion Golovushkin

Reputation: 241

You can use audio tag instead of embed.
Example: http://codepen.io/anon/pen/LxaLMO

HTML

<div id="pictures">     
<img name="http://developer.mozilla.org/@api/deki/files/2926/=AudioTest_(1).ogg" src="http://megaicons.net/static/img/icons_sizes/8/178/256/numbers-1-filled-icon.png" class="card"       id="sir-finly" alt="" />
<img name="http://developer.mozilla.org/@api/deki/files/2926/=AudioTest_(2).ogg" src="http://www.freeiconspng.com/uploads/number-2-two-icon-13.png"    class="card" id="shifterzerus" alt="" />
<audio id="player" src="" autoplay></audio>

JS

    $(document).ready( function() {
    $('.card').click(function(){
        $('#player').attr('src', $(this).attr('name'));
    });
});

Documentation: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio

Upvotes: 1

Related Questions