Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MotiurRahman/a47344a2199c2edf2ede0ff9dec5bbec to your computer and use it in GitHub Desktop.
Save MotiurRahman/a47344a2199c2edf2ede0ff9dec5bbec to your computer and use it in GitHub Desktop.
iOS audio player scrubbing in Titanium
var isPlaying = false;
var win = Ti.UI.createWindow({
backgroundColor: '#fff'
});
var btn = Ti.UI.createButton({
title: 'Play',
top: 60
});
var audio = Ti.Media.createSound({url: 'sound.wav'});
var slider = Ti.UI.createSlider({min: 0, max: 1, width: 200, tintColor: "#af1327"});
btn.addEventListener('click', function() {
if (isPlaying) {
audio.reset();
slider.setValue(0);
btn.setTitle('Play');
} else {
audio.play();
btn.setTitle('Reset');
}
isPlaying = !isPlaying;
});
slider.addEventListener('change', function(e) {
audio.setTime(audio.duration * e.value * 1000); // It's in ms
audio.play();
});
win.add(btn);
win.add(slider);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment