Android issues: mp3 stream createAudioPlayer
Ti SDK 1.3.0
Android 2.1 update
Audio issue: Audio does not update url.
Loading a mp3 to stream using createAudioPlayer. using setUrl() or prop url should change the audio stream.
The url shows a change but initial audio still loads and plays.
//... load xml, place objects and trigger setData()
var sound = Ti.Media.createAudioPlayer();
sound.addEventListener('change', function(e){
if(sound.state == 3){
playBtn.image = imgPause;
actInd.hide();
}
else{
playBtn.image = imgPlay;
}
});
sound.addEventListener('error', function(e){
// an error is always detected.
//"Unknown media error" is the one when no audio plays
if(e.message == "Unknown media error"){
alert("Error Playing Audio, Skipping: " + e.message);
actInd.hide();
nextSong();
}
});
sound.addEventListener('complete', function(){ nextSong(); });
sound.addEventListener('resume', function(){
Titanium.API.info('Resume ');
});
sound.addEventListener('progress', function(e){
//Titanium.API.info('Time Played: ' + Math.round(e.progress) + ' seconds' + " " + sound.state + " " + sound.paused + " " + sound.duration);
actInd.hide();
});
function setData(d){
// OMMITTED CODE
// set vars from passed in data
loadAudio(audioUrl);
artistTxt.text = artist;
titleTxt.text = title;
nextTxt.text = "Next: " + d.item(currentSong+1).getElementsByTagName("artist").item(0).childNodes.item(0).nodeValue + " \"" + d.item(currentSong+1).getElementsByTagName("title").item(0).childNodes.item(0).nodeValue+"\"";
}
function loadAudio(s){
actInd.show();
actInd.message = "Loading Audio...";
sound.stop();
sound.allowBackground = true;
sound.setUrl(s);
sound.url = s;
sound.start();
}
The above would only play one mp3 regardless of how I set the url. So I tried to create a new audio player (below code) for each new song by overwriting the sound object. The issue here is the audio does not play consistent. I get onEvent errors for each load. Sometimes 2, sometimes 3. Some are "Unknown media issue" or "Unknown media error". The "Unkown media issue" error would play. But the Unknown media error would never play. Any ideas?
// only change is position of sound listeners and create new audio for every load.
var sound = Ti.Media.createAudioPlayer();
function loadAudio(s){
actInd.show();
actInd.message = "Loading Audio...";
sound.stop();
sound = Titanium.Media.createAudioPlayer({url:s,preload:true,allowBackground:true});
sound.addEventListener('change', function(e){
if(sound.state == 3){
playBtn.image = imgPause;
actInd.hide();
}
else{
playBtn.image = imgPlay;
}
});
sound.addEventListener('error', function(e){
// an error is always detected.
//"Unknown media error" is the one when no audio plays
if(e.message == "Unknown media error"){
alert("Error Playing Audio, Skipping: " + e.message);
actInd.hide();
nextSong();
}
});
sound.addEventListener('complete', function(){ nextSong(); });
sound.addEventListener('resume', function(){
Titanium.API.info('Resume ');
});
sound.addEventListener('progress', function(e){
//Titanium.API.info('Time Played: ' + Math.round(e.progress) + ' seconds' + " " + sound.state + " " + sound.paused + " " + sound.duration);
actInd.hide();
});
sound.start();
}
Is this a bug for android or am I doing something wrong?
4 Answers
-
I worked around this by creating a new AudioPlayer for each audio clip played.
if (audioPlayer) { audioPlayer.stop(); audioPlayer = null; } audioPlayer = Titanium.Media.createAudioPlayer({}); audioPlayer.addEventListener('change', playbackStateChange); audioPlayer.addEventListener('progress', progressChange); audioPlayer.setUrl(url); audioPlayer.start();
-
'progress' fails on Andriod but rounds properly on iPhone.
4.123 becomes 4 on iPhone when rounded but 4123 on Android.Math.round(e.progress)
-
how is this progressing? any solutions so far?
-
Hi all! I am creating an app that plays various voiceover sounds. Each sound must wait for the last one to finish before it is played. This works fine on the iPhone, but on Android it clips off the sounds. I am using Ti.Media.createSound instead of createAudioPlayer. Does this matter? Any clues?