Last active
January 3, 2017 18:20
-
-
Save hansemannn/fff86dec7e8b7d65ca7ea4f15276ad46 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