package com.sedmelluq.discord.lavaplayer.container.mp3;

import com.sedmelluq.discord.lavaplayer.tools.io.SeekableInputStream;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import com.sedmelluq.discord.lavaplayer.track.BaseAudioTrack;
import com.sedmelluq.discord.lavaplayer.track.playback.AudioTrackExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Audio track that handles an MP3 stream
 */
public class Mp3AudioTrack extends BaseAudioTrack {
  private static final Logger log = LoggerFactory.getLogger(Mp3AudioTrack.class);

  private final SeekableInputStream inputStream;

  /**
   * @param executor Track executor
   * @param trackInfo Track info
   * @param inputStream Input stream for the MP3 file
   */
  public Mp3AudioTrack(AudioTrackExecutor executor, AudioTrackInfo trackInfo, SeekableInputStream inputStream) {
    super(executor, trackInfo);

    this.inputStream = inputStream;
  }

  @Override
  public void process(AtomicInteger volumeLevel) throws Exception {
    Mp3StreamingFile file = new Mp3StreamingFile(inputStream, executor.getFrameConsumer(), volumeLevel);
    file.parseHeaders();

    log.debug("Starting to play MP3 track {}", getIdentifier());

    try {
      executor.executeProcessingLoop(file::provideFrames, file::seekToTimecode);
    } finally {
      file.close();
    }
  }
}

@@ -1170,16 +1170,29 @@
 Level);%0A
+%0A    try %7B%0A  
     file
@@ -1205,24 +1205,26 @@
 Headers();%0A%0A
+  
     log.debu
@@ -1275,27 +1275,16 @@
 fier());
-%0A%0A    try %7B
 %0A      e

Fix MP3 track not closed when header parsing fails.