-
-
Save MotiurRahman/a47344a2199c2edf2ede0ff9dec5bbec to your computer and use it in GitHub Desktop.
iOS audio player scrubbing in Titanium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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