Last active
August 29, 2015 14:03
-
-
Save Amimul100/be7105880d7c082e4b8b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Hi, Here is a example i Tested in Both iOS and in Android. | |
Test Result: | |
In iOS AudioPlayer progress event stops firing when state changes to stopping. | |
STEPS TO TEST | |
1. Create a new project | |
2. Update app.js file with sample code | |
4. And run on Android emulator and iOS simulator | |
5. remote audio will play. | |
~~~ | |
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: 'https://ia600200.us.archive.org/1/items/testmp3testfile/mpthreetest.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(); | |
~~~ | |
Now in Android the output is | |
~~~ | |
[INFO] : State: starting (4) | |
[INFO] : State: initialized (1) | |
[INFO] : State: playing (3) | |
[INFO] : Time Played: 1019 milliseconds | |
[INFO] : Time Played: 2038 milliseconds | |
[INFO] : Time Played: 3004 milliseconds | |
[INFO] : Time Played: 4023 milliseconds | |
[INFO] : Time Played: 4989 milliseconds | |
[INFO] : Time Played: 6034 milliseconds | |
[INFO] : Time Played: 7001 milliseconds | |
[INFO] : Time Played: 8020 milliseconds | |
[INFO] : Time Played: 8986 milliseconds | |
[INFO] : Time Played: 10005 milliseconds | |
[INFO] : Time Played: 11050 milliseconds | |
[INFO] : Time Played: 12016 milliseconds | |
[INFO] : State: stopping (6) | |
[INFO] : State: stopped (5) | |
~~~ | |
and in IOS the output is | |
~~~ | |
[INFO] : State: starting (1) | |
[INFO] : State: waiting_for_data (2) | |
[INFO] : State: waiting_for_queue (3) | |
[INFO] : State: playing (4) | |
[INFO] : Time Played: 360 milliseconds | |
[INFO] : Time Played: 1360 milliseconds | |
[INFO] : Time Played: 2361 milliseconds | |
[INFO] : Time Played: 3360 milliseconds | |
[INFO] : Time Played: 4360 milliseconds | |
[INFO] : Time Played: 5361 milliseconds | |
[INFO] : Time Played: 6360 milliseconds | |
[INFO] : Time Played: 7360 milliseconds | |
[INFO] : Time Played: 8361 milliseconds | |
[INFO] : Time Played: 9360 milliseconds | |
[INFO] : State: stopping (6) | |
[INFO] : State: stopped (7) | |
[INFO] : State: initialized (0) | |
~~~ | |
Now to your Query, in IOS AUDIO IS 12 SECONDS LONG BUT ONLY SHOWS PROGRESS TO 9 SECONDS. This is because in IOS playing a remote audio file will buffer and play at the same time. where in android first the remote audio file is loaded and them played. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment