
Originally Posted by
jscheuer1
Ah, but now I see and remember that we already converted to touchstart from tap:
Code:
if(istouch){
document.getElementById(this.getAttribute('data-trigger')).addEventListener('touchstart', playstop, false);
} else {
$('#' + this.getAttribute('data-trigger')).click(playstop);
}
That's probably why this is happening. Try replacing the above with:
Code:
if(istouch){
var dt = document.getElementById(this.getAttribute('data-trigger'));
dt.addEventListener('touchstart', function(e){e.preventDefault(); this.setAttribute('data-start', new Date().getTime())}, false);
dt.addEventListener('touchend', function(e){
var ds;
if(ds = this.getAttribute('data-start') && new Date().getTime() - ds < 100){
playstop.apply(this, [e]);
}
}, false);
} else {
$('#' + this.getAttribute('data-trigger')).click(playstop);
}
I can't test it because I'm not on a mobile. It doesn't throw any obvious errors though. I chose 100 milliseconds (red in the above) as the duration, if the tap lasts longer than that, it's assumed to be something else. That number may need to be increased or decreased.
Hi John,
Thanks for the help. I tried it with 100ms and it didn't work - i.e. no sound and also no swipe on my droid phone, although it plays a sound with a click on my PC. So, I tried 500ms and also 1000 ms, assuming I wasn't tapping fast enough so increased the threshold. This gave the same result - no click and no swipe on the phone. Below is the code - I can put this online if that helps, just let me know.
Code:
<script type="text/javascript">
jQuery(function($){
var highlight = 'yellow', origcolor = 'transparent', istouch = !!('ontouchstart' in window) || !!('ontouchstart' in document.documentElement) || !!window.ontouchstart || (!!window.Touch && !!window.Touch.length) || !!window.onmsgesturechange || (window.DocumentTouch && window.document instanceof window.DocumentTouch);
var $s = $('.spanish').each(function(i, snd){
$(snd).jPlayer({
ready: function() {
$(snd).jPlayer("setMedia", {
mp3: snd.href,
ogg: snd.href.replace(/\.mp3$/, '.ogg')
});
var playstop = function (e) {
e && e.preventDefault();
var $this = $(this);
if(!$this.data('play')){
$this.stop(true, true).css({backgroundColor: highlight});
var $playing = $('a[data-playing="true"]');
if($playing.length){
if(istouch){
playstop.apply($playing.get(0));
} else {
$playing.trigger('click');
}
}
} else {
$this.stop(true, true).animate({backgroundColor: origcolor}, 1000);
}
$(snd).jPlayer($this.data('play')? "stop" : "play");
$this.data('play', !$this.data('play'));
$this.attr('data-playing', $this.data('play'));
};
if(istouch){
var dt = document.getElementById(this.getAttribute('data-trigger'));
dt.addEventListener('touchstart', function(e){e.preventDefault(); this.setAttribute('data-start', new Date().getTime())}, false);
dt.addEventListener('touchend', function(e){
var ds;
if(ds = this.getAttribute('data-start') && new Date().getTime() - ds < 1000){
playstop.apply(this, [e]);
}
}, false);
} else {
$('#' + this.getAttribute('data-trigger')).click(playstop);
}
},
ended: function(){
$('#' + this.getAttribute('data-trigger')).attr('data-playing', 'false').data('play', false).stop(true, true).animate({backgroundColor: origcolor}, 1000);
},
swfPath: "./"
});
});
});
</script>
Bookmarks