// Path: app/src/main/java/com/mypodcasts/episodes/EpisodeFile.java
// public class EpisodeFile {
//   private final ExternalPublicFileLookup externalPublicFileLookup;
// 
//   @Inject
//   public EpisodeFile(ExternalPublicFileLookup externalPublicFileLookup) {
//     this.externalPublicFileLookup = externalPublicFileLookup;
//   }
// 
//   public boolean exists(Episode episode) {
//     return externalPublicFileLookup.exists(
//         getExternalStoragePublicDirectory(getPodcastsDirectory()),
//         episode.getAudioFilePath()
//     );
//   }
// 
//   public String getAudioFilePath(Episode episode) {
//     if (exists(episode)) {
//       return format(
//           "%s/%s",
//           getExternalStoragePublicDirectory(getPodcastsDirectory()),
//           episode.getAudioFilePath()
//       );
//     }
// 
//     return episode.getAudioUrl();
//   }
// 
//   public String getPodcastsDirectory() {
//     return DIRECTORY_PODCASTS;
//   }
// }
// 
// Path: app/src/main/java/com/mypodcasts/player/events/AudioPlayingEvent.java
// public class AudioPlayingEvent {
//   private final AudioPlayer audioPlayer;
// 
//   public AudioPlayingEvent(AudioPlayer audioPlayer) {
//     this.audioPlayer = audioPlayer;
//   }
// 
//   public AudioPlayer getAudioPlayer() {
//     return audioPlayer;
//   }
// }
// 
// Path: app/src/main/java/com/mypodcasts/repositories/models/Episode.java
// public class Episode implements Serializable {
// 
//   private String title;
//   private String publishedDate;
//   private String description;
//   private String duration;
//   private Audio audio;
//   private Feed podcast;
//   private Image image;
// 
//   public Image getImage() {
//     return image;
//   }
// 
//   public String getTitle() {
//     return title;
//   }
// 
//   public Date getPublishedDate() {
//     if (publishedDate == null) { return null; }
// 
//     return dateTimeParser().parseDateTime(publishedDate).toDate();
//   }
// 
//   public String getDescription() {
//     return description == null ? "" : description;
//   }
// 
//   public String getDuration() {
//     return duration;
//   }
// 
//   public Feed getFeed() {
//     if (podcast == null) { return new Feed(); }
// 
//     return podcast;
//   }
// 
//   public String getAudioFilePath() {
//     return getFeed().getId() + "/" + getTitle() + ".mp3";
//   }
// 
//   public String getAudioUrl() {
//     return getAudio().getUrl();
//   }
// 
//   public String getAudioLength() {
//     return getAudio().getLength();
//   }
// 
//   protected Audio getAudio() {
//     if (audio == null) { return new EmptyAudio(); }
// 
//     return audio;
//   }
// 
//   @Override
//   public String toString() {
//     return format(
//         "{ \"title\": %s, " +
//             "\"audioFilePath\": %s, " +
//             "\"feed\": { \"id\": %s, \"title\": %s } " +
//         "}",
//         getTitle(),
//         getAudioFilePath(),
//         getFeed().getId(),
//         getFeed().getTitle()
//     );
//   }
// 
//   private class EmptyAudio extends Audio {
//     @Override
//     public String getUrl() {
//       return "";
//     }
// 
//     @Override
//     public String getLength() {
//       return "0";
//     }
//   }
// }


import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.widget.MediaController.MediaPlayerControl;
import com.mypodcasts.episodes.EpisodeFile;
import com.mypodcasts.player.events.AudioPlayingEvent;
import com.mypodcasts.repositories.models.Episode;
import java.io.IOException;
import javax.inject.Inject;
import org.greenrobot.eventbus.EventBus;
import static android.media.AudioManager.STREAM_MUSIC;
package com.mypodcasts.player;







public class AudioPlayer implements MediaPlayerControl, OnPreparedListener {

  private final MediaPlayer mediaPlayer;
  private final EventBus eventBus;
  private final EpisodeFile episodeFile;

  @Inject
  public AudioPlayer(MediaPlayer mediaPlayer, EventBus eventBus, EpisodeFile episodeFile) {
    this.mediaPlayer = mediaPlayer;
    this.eventBus = eventBus;
    this.episodeFile = episodeFile;
  }

// Path: app/src/main/java/com/mypodcasts/episodes/EpisodeFile.java
// public class EpisodeFile {
//   private final ExternalPublicFileLookup externalPublicFileLookup;
// 
//   @Inject
//   public EpisodeFile(ExternalPublicFileLookup externalPublicFileLookup) {
//     this.externalPublicFileLookup = externalPublicFileLookup;
//   }
// 
//   public boolean exists(Episode episode) {
//     return externalPublicFileLookup.exists(
//         getExternalStoragePublicDirectory(getPodcastsDirectory()),
//         episode.getAudioFilePath()
//     );
//   }
// 
//   public String getAudioFilePath(Episode episode) {
//     if (exists(episode)) {
//       return format(
//           "%s/%s",
//           getExternalStoragePublicDirectory(getPodcastsDirectory()),
//           episode.getAudioFilePath()
//       );
//     }
// 
//     return episode.getAudioUrl();
//   }
// 
//   public String getPodcastsDirectory() {
//     return DIRECTORY_PODCASTS;
//   }
// }
// 
// Path: app/src/main/java/com/mypodcasts/player/events/AudioPlayingEvent.java
// public class AudioPlayingEvent {
//   private final AudioPlayer audioPlayer;
// 
//   public AudioPlayingEvent(AudioPlayer audioPlayer) {
//     this.audioPlayer = audioPlayer;
//   }
// 
//   public AudioPlayer getAudioPlayer() {
//     return audioPlayer;
//   }
// }
// 
// Path: app/src/main/java/com/mypodcasts/repositories/models/Episode.java
// public class Episode implements Serializable {
// 
//   private String title;
//   private String publishedDate;
//   private String description;
//   private String duration;
//   private Audio audio;
//   private Feed podcast;
//   private Image image;
// 
//   public Image getImage() {
//     return image;
//   }
// 
//   public String getTitle() {
//     return title;
//   }
// 
//   public Date getPublishedDate() {
//     if (publishedDate == null) { return null; }
// 
//     return dateTimeParser().parseDateTime(publishedDate).toDate();
//   }
// 
//   public String getDescription() {
//     return description == null ? "" : description;
//   }
// 
//   public String getDuration() {
//     return duration;
//   }
// 
//   public Feed getFeed() {
//     if (podcast == null) { return new Feed(); }
// 
//     return podcast;
//   }
// 
//   public String getAudioFilePath() {
//     return getFeed().getId() + "/" + getTitle() + ".mp3";
//   }
// 
//   public String getAudioUrl() {
//     return getAudio().getUrl();
//   }
// 
//   public String getAudioLength() {
//     return getAudio().getLength();
//   }
// 
//   protected Audio getAudio() {
//     if (audio == null) { return new EmptyAudio(); }
// 
//     return audio;
//   }
// 
//   @Override
//   public String toString() {
//     return format(
//         "{ \"title\": %s, " +
//             "\"audioFilePath\": %s, " +
//             "\"feed\": { \"id\": %s, \"title\": %s } " +
//         "}",
//         getTitle(),
//         getAudioFilePath(),
//         getFeed().getId(),
//         getFeed().getTitle()
//     );
//   }
// 
//   private class EmptyAudio extends Audio {
//     @Override
//     public String getUrl() {
//       return "";
//     }
// 
//     @Override
//     public String getLength() {
//       return "0";
//     }
//   }
// }


// Path: app/src/main/java/com/mypodcasts/player/AudioPlayer.java
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.widget.MediaController.MediaPlayerControl;
import com.mypodcasts.episodes.EpisodeFile;
import com.mypodcasts.player.events.AudioPlayingEvent;
import com.mypodcasts.repositories.models.Episode;
import java.io.IOException;
import javax.inject.Inject;
import org.greenrobot.eventbus.EventBus;
import static android.media.AudioManager.STREAM_MUSIC;

package com.mypodcasts.player;







public class AudioPlayer implements MediaPlayerControl, OnPreparedListener {

  private final MediaPlayer mediaPlayer;
  private final EventBus eventBus;
  private final EpisodeFile episodeFile;

  @Inject
  public AudioPlayer(MediaPlayer mediaPlayer, EventBus eventBus, EpisodeFile episodeFile) {
    this.mediaPlayer = mediaPlayer;
    this.eventBus = eventBus;
    this.episodeFile = episodeFile;
  }

  public MediaPlayer play(Episode episode) throws IOException {