Skip to content

Instantly share code, notes, and snippets.

@hansemannn
Last active January 3, 2017 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hansemannn/fff86dec7e8b7d65ca7ea4f15276ad46 to your computer and use it in GitHub Desktop.
Save hansemannn/fff86dec7e8b7d65ca7ea4f15276ad46 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