Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Commit

Permalink
Catch decoder thread exceptions and fail
Browse files Browse the repository at this point in the history
  • Loading branch information
mfietz committed Mar 3, 2016
1 parent d6e4939 commit 9b4f648
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions library/src/main/java/org/antennapod/audio/SonicAudioPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -725,24 +725,14 @@ public void run() {
mTrack.release();
final MediaFormat oFormat = mCodec.getOutputFormat();
Log.d("PCM", "Output format has changed to " + oFormat);
try {
int sampleRate = oFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE);
Log.d(TAG, "new sample rate: " + sampleRate);
int channelCount = oFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
Log.d(TAG, "new channel count: " + channelCount);
if(sampleRate > 0 && channelCount > 0) {
initDevice(sampleRate, channelCount);
outputBuffers = mCodec.getOutputBuffers();
}
} catch(Throwable t) {
Log.e(TAG, Log.getStackTraceString(t));
error();
}
if(mTrack.getState() != AudioTrack.STATE_INITIALIZED) {
error();
} else {
mTrack.play();
int sampleRate = oFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE);
int channelCount = oFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
if (sampleRate != mSonic.getSampleRate() ||
channelCount != mSonic.getNumChannels()) {
initDevice(sampleRate, channelCount);
outputBuffers = mCodec.getOutputBuffers();
}
mTrack.play();
mLock.unlock();
}
} while (res == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED ||
Expand Down Expand Up @@ -790,6 +780,13 @@ public void run() {
}
}
});
mDecoderThread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Log.e(TAG_TRACK, Log.getStackTraceString(ex));
error();
}
});
mDecoderThread.setDaemon(true);
mDecoderThread.start();
}
Expand Down

0 comments on commit 9b4f648

Please sign in to comment.