lundi 23 mars 2015

UDP activated sound is intermittent


I have a UDP activated routine which accepts a specific datagram packet and starts playing a 10-second long alert sound. Testing the code on a Toshiba Android TV (L5400) appears to be OK, a message is sent every 12 seconds. All hell broke loose when someone decided to randomly send a series of UDP packets at 5 - 8 seconds apart for stress testing.


After a while, the sound just simply disappears from the TV. If I turn off the random burst of UDP packets, the sound returns shortly. I am baffled because I have tried running the same code and test case on my Samsung Tab 4 tablet; using the tablet to emulate my Android TV, I discover absolutely no problems with the sound.


Does anybody have any idea as to why the sound might be disappearing on the Android TV?


I have attached parts of the code below.



private class ReceiveTask extends AsyncTask<Void, Void, Void> {
...
while (bKeepRunning) {
s.receive(p); //s is a DatagramSocket and p is a DatagramPacket
message = new String(buffer, 0, p.getLength());
lastMessage = message;
runOnUiThread(updateTextMessage);
}
...
}

private Runnable updateTextMessage = new Runnable() {
public void run() {
...
dosomething();
playSound();
dosomethingelse();
...
}
};

private void playSound() {
if(!isPlaying1){
mp1 = new MediaPlayer();
mp1 = MediaPlayer.create(context, R.raw.alert);
mp1.start();
isPlaying1 = true;
}else{
isPlaying1 = false;
if(mp1.isPlaying()) {
mp1.stop();
}
mp1.reset();
mp1 = MediaPlayer.create(context, R.raw.alert);
mp1.start();
isPlaying1 = true;
}
mp1.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp1) {
mp1.release();
isPlaying1 = false;
}
});
}




Aucun commentaire:

Enregistrer un commentaire