My android application plays a radio through MMS Stream using AudioTrack class as described here
The Problem is that after playing first chunk the device doesn't get any audio output.
Here is the logcat info that may be useful
DEBUG/WifiService(1904): ACTION_BATTERY_CHANGED pluggedType: 2
11-12 11:21:07.953: INFO/Hello(2821): There
11-12 11:21:07.958: INFO/Get Current Player State(2821): 3
11-12 11:21:07.958: INFO/Paused(2821): 2
11-12 11:21:07.958: INFO/Playing(2821): 3
11-12 11:21:07.958: INFO/Stopped(2821): 1
11-12 11:21:07.963: INFO/Size(2821): 7864364
11-12 11:21:08.023: DEBUG/dalvikvm(2821): GC freed 103 objects / 4184 bytes in 62ms
11-12 11:21:08.078: INFO/dalvikvm-heap(2821): Gro开发者_JAVA技巧w heap (frag case) to 14.770MB for 7864380-byte allocation
11-12 11:21:08.153: DEBUG/dalvikvm(2821): GC freed 0 objects / 0 bytes in 74ms
11-12 11:21:08.273: ERROR/AudioPolicyManager(1868): [HJ] isDuplicated = 0
11-12 11:21:08.273: ERROR/AudioPolicyManager(1868): 1.[HJ] Headset Volume = 0.354813 , device = 4
11-12 11:21:08.273: INFO/Offset(2821): 11837528
Here is the code (It's the method itself which called periodically from C code)
boolean b = false;
Log.i("Hello", "There");
if (at != null) {
Log.i("Comparing", "" + at.getPlayState());
Log.i("Paused", "" + AudioTrack.PLAYSTATE_PAUSED);
Log.i("Playing", "" + AudioTrack.PLAYSTATE_PLAYING);
Log.i("Stopped", "" + AudioTrack.PLAYSTATE_STOPPED);
b = at.getPlayState() != AudioTrack.PLAYSTATE_PLAYING;
}
try {
if (!b) {
int intSize = android.media.AudioTrack.getMinBufferSize(33075,
AudioFormat.CHANNEL_CONFIGURATION_STEREO,
AudioFormat.ENCODING_PCM_16BIT);
at = new AudioTrack(AudioManager.STREAM_MUSIC, 33075,
AudioFormat.CHANNEL_CONFIGURATION_STEREO,
AudioFormat.ENCODING_PCM_16BIT, intSize * 20,
AudioTrack.MODE_STREAM);
}
if (at == null) {
Log.d("TCAudio", "audio track is not initialised ");
return;
}
// 512 kb
// Reading the file..
byte[] byteData = null;
if (file == null)
file = new File("/sdcard/outmms.wav");
int size = (int) file.length();
Log.i("Size", "" + size);
byteData = new byte[size];
FileInputStream in = null;
try {
in = new FileInputStream(file);
in.read(byteData);
// if (!b) {
at.play();
// }
at.write(byteData, offset, byteData.length);
offset += byteData.length;
Log.i("Offset", "" + offset);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
精彩评论