Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-20140] Android: Fix Streaming Audio on Android 6.0 #7591

Merged
merged 1 commit into from Dec 17, 2015

Conversation

ashcoding
Copy link
Contributor

Jira: https://jira.appcelerator.org/browse/TIMOB-20140

Test code app.js to be tested on Android 6.0 device

var win = Titanium.UI.createWindow({
title:'Audio Test',
backgroundColor:'#fff',
layout: 'vertical'
});
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://icecast.omroep.nl/3fm-bb-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) {
Ti.API.info('Time Played: ' + Math.round(e.progress) + ' 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();

@hieupham007
Copy link
Contributor

Code reviewed and functionally tested. Request accepted

hieupham007 added a commit that referenced this pull request Dec 17, 2015
[TIMOB-20140] Android: Fix Streaming Audio on Android 6.0
@hieupham007 hieupham007 merged commit 6bfd40d into tidev:master Dec 17, 2015
@cheekiatng
Copy link
Contributor

@ashcoding it would have been better if there's some unit test in this.

@ashcoding
Copy link
Contributor Author

Noted. @cheekiatng

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants