Skip to content

Commit

Permalink
Simplify audio track initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
protyposis committed Jan 2, 2017
1 parent df8bca6 commit ae14207
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,6 @@ public void setDataSource(Context context, Uri uri) throws IOException {
}

private void prepareInternal() throws IOException, IllegalStateException {
if (mAudioFormat != null) {
mAudioPlayback = new AudioPlayback();
// Initialize settings in case they have already been set before the preparation
mAudioPlayback.setAudioSessionId(mAudioSessionId);
setVolume(mVolumeLeft, mVolumeRight); // sets the volume on mAudioPlayback
}

MediaCodecDecoder.OnDecoderEventListener decoderEventListener = new MediaCodecDecoder.OnDecoderEventListener() {
@Override
public void onBuffering(MediaCodecDecoder decoder) {
Expand Down Expand Up @@ -324,13 +317,19 @@ public void onBuffering(MediaCodecDecoder decoder) {
}

if(mAudioTrackIndex != MediaCodecDecoder.INDEX_NONE) {
mAudioPlayback = new AudioPlayback();
// Initialize settings in case they have already been set before the preparation
mAudioPlayback.setAudioSessionId(mAudioSessionId);
setVolume(mVolumeLeft, mVolumeRight); // sets the volume on mAudioPlayback

try {
boolean passive = (mAudioExtractor == mVideoExtractor || mAudioExtractor == null);
MediaCodecDecoder ad = new MediaCodecAudioDecoder(mAudioExtractor != null ? mAudioExtractor : mVideoExtractor,
passive, mAudioTrackIndex, decoderEventListener, mAudioPlayback);
mDecoders.addDecoder(ad);
} catch (Exception e) {
Log.e(TAG, "cannot create audio decoder: " + e.getMessage());
mAudioPlayback = null;
}
}

Expand Down

0 comments on commit ae14207

Please sign in to comment.