This seems to work pretty well (I ended up using .ogg as well as .mp3 - the .ogg might be required by some browsers):
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script type="text/javascript" src="jquery.jplayer.min.js"></script>
<script type="text/javascript">
jQuery(function($){
var highlight = 'yellow', origcolor = 'white', click = document.ontouchstart === undefined ? 'click' : 'touchstart';
var $s = $('.spanish').each(function(i, snd){
$(snd).jPlayer({
ready: function() {
$(snd).jPlayer("setMedia", {
mp3: snd.href,
ogg: snd.href.replace(/\.mp3$/, '.ogg')
});
var kickoff = function (e) {
e && e.preventDefault();
var $this = $(this);
if(!$this.data('play')){
$this.stop(true, true).css({backgroundColor: highlight}).animate({backgroundColor: origcolor}, 5000);
var $playing = $('a[data-playing="true"]');
if($playing.length){
if(click === 'click'){$playing.trigger('click');}
else {$playing.data('kickoff').apply($playing.get(0));}
}
} else {
$this.stop(true, true).css({backgroundColor: origcolor});
}
$(snd).jPlayer($this.data('play')? "stop" : "play");
$this.data('play', !$this.data('play'));
$this.attr('data-playing', $this.data('play'));
};
if(click === 'click'){
$('#' + this.getAttribute('data-trigger')).click(kickoff);
} else {
$('#' + this.getAttribute('data-trigger')).data('kickoff', kickoff);
document.getElementById(this.getAttribute('data-trigger')).addEventListener(click, kickoff, true);
}
},
ended: function(){
$('#' + this.getAttribute('data-trigger')).attr('data-playing', 'false').data('play', false);
},
swfPath: "./"
});
});
});
</script>
</head>
<body>
<a class="spanish" data-trigger="guitar" href="p1rj1s_-_rockGuitar.mp3">Guitar</a>
<a id="guitar" href="#">Guitar</a><br>
<a class="spanish" data-trigger="cromag" href="TSP-01-Cro_magnon_man.mp3">Guitar</a>
<a id="cromag" href="#">Cro Magnum Man</a>
</body>
</html>
Demo:
http://home.comcast.net/~jscheuer1/s...layer/demo.htm
I'm not certain it will work on touch devices or not. Try it out for me, I have none. If not, we can probably either tweak it or incorporate the jQuery mobile plugin.
As I thought about it more though, I don't think touch devices have any problem with ordinary click events if they're on specific elements like these are. So I made up a demo with that in mind and switched things around a little and used an icon and css to jazz it up as well:
http://home.comcast.net/~jscheuer1/s...ayer/demo2.htm
Bookmarks