Last active
December 24, 2015 00:59
-
-
Save samcleaver/6720370 to your computer and use it in GitHub Desktop.
TIMOB-10212
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
/* | |
* | |
* Sam's Test Case | |
* (It's essentially just the example given for audioPlayer in the docs | |
* with getDuration added to the progress event listener.) | |
* getDuration() Call | |
* 0.1 | |
*/ | |
//Create an audioPlayer | |
var win = Titanium.UI.createWindow({ | |
title:'Audio Test', | |
backgroundColor:'#333', | |
layout: 'vertical', | |
navBarHidden:true, | |
exitOnClose:true | |
}); | |
var startStopButton = Titanium.UI.createButton({ | |
title:'Start/Stop Streaming', | |
top:10, | |
width:200, | |
height:40 | |
}); | |
var pauseResumeButton = Titanium.UI.createButton({ | |
title:'Pause/Resume Streaming', | |
top:10, | |
width:200, | |
height:40, | |
enabled:false | |
}); | |
win.add(startStopButton); | |
win.add(pauseResumeButton); | |
// allowBackground: true on Android allows the | |
// player to keep playing when the app is in the | |
// background. | |
var audioPlayer = Ti.Media.createAudioPlayer({ | |
url: 'http://appcelerator.qe.test.data.s3.amazonaws.com/KSResources/audio/audio_session.mp3', | |
allowBackground: true | |
}); | |
startStopButton.addEventListener('click',function() { | |
// When paused, playing returns false. | |
// If both are false, playback is stopped. | |
if (audioPlayer.playing || audioPlayer.paused) | |
{ | |
audioPlayer.stop(); | |
pauseResumeButton.enabled = false; | |
if (Ti.Platform.name === 'android') | |
{ | |
audioPlayer.release(); | |
} | |
} | |
else | |
{ | |
audioPlayer.start(); | |
pauseResumeButton.enabled = true; | |
} | |
}); | |
pauseResumeButton.addEventListener('click', function() { | |
if (audioPlayer.paused) { | |
audioPlayer.start(); | |
} | |
else { | |
audioPlayer.pause(); | |
} | |
}); | |
audioPlayer.addEventListener('progress',function(e) { | |
///////PART THAT TESTS GETDURATION//////// | |
Ti.API.info('Time Played: ' + Math.round(e.progress) + '/' + audioPlayer.getDuration() + 'milliseconds'); | |
}); | |
audioPlayer.addEventListener('change',function(e) | |
{ | |
Ti.API.info('State: ' + e.description + ' (' + e.state + ')'); | |
}); | |
win.addEventListener('close',function() { | |
audioPlayer.stop(); | |
if (Ti.Platform.osname === 'android') | |
{ | |
audioPlayer.release(); | |
} | |
}); | |
win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment