// Path: app/src/main/java/com/architjn/audiobook/bean/BookChapter.java
// public class BookChapter implements Serializable{
//     private String id;
//     private String title;
//     private long duration;
//     private String data;
//     private long currDuration;
// 
//     public BookChapter() {
//         //for serializable
//     }
// 
//     public BookChapter(String id, String title, long duration, String data, long currDuration) {
//         this.id = id;
//         this.title = title;
//         this.duration = duration;
//         this.data = data;
//         this.currDuration = currDuration;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public long getDuration() {
//         return duration;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public void setTitle(String title) {
//         this.title = title;
//     }
// 
//     public void setDuration(long duration) {
//         this.duration = duration;
//     }
// 
//     public String getData() {
//         return data;
//     }
// 
//     public void setData(String data) {
//         this.data = data;
//     }
// 
//     public long getCurrDuration() {
//         return currDuration;
//     }
// 
//     public void setCurrDuration(long currDuration) {
//         this.currDuration = currDuration;
//     }
// }
// 
// Path: app/src/main/java/com/architjn/audiobook/interactor/PlayerInteractor.java
// public class PlayerInteractor {
// 
//     private static PlayerInteractor instance;
// 
//     private final Context context;
//     private final DBHelper db;
//     private IPlayerPresenter presenter;
//     private IPlayerService service;
//     private Status status;
//     private AudioBook audiobook;
//     private int chapterNo = 0;
// 
//     public static PlayerInteractor getInstance(Context context) {
//         if (instance == null)
//             instance = new PlayerInteractor(context);
//         return instance;
//     }
// 
//     private PlayerInteractor(Context context) {
//         this.context = context;
//         this.db = DBHelper.getInstance(context);
//     }
// 
//     public void setPresenterListener(IPlayerPresenter presenter) {
//         this.presenter = presenter;
//     }
// 
//     public void setServiceListener(IPlayerService service) {
//         this.service = service;
//     }
// 
//     public AudioBook loadBook(String albumId) {
//         audiobook = db.getAudioBookViaId(albumId);
//         if (service != null && audiobook != null)
//             service.setSource(audiobook.getChapters().get(chapterNo));
//         return audiobook;
//     }
// 
//     public int playBook() {
//         if (service != null)
//             return service.play();
//         else return -1;
//     }
// 
//     public void setStatus(Status status) {
//         this.status = status;
//     }
// 
//     public Status getStatus() {
//         return status;
//     }
// 
//     public BookChapter getNextChapter() {
//         if (audiobook != null && audiobook.getChapters().size() > chapterNo)
//             return audiobook.getChapters().get(chapterNo);
//         else return null;
//     }
// 
//     public void askToPlay() {
//         presenter.playSong();
//     }
// 
//     public void updateSeek(int progress) {
//         if (service!=null)
//             service.onSeekChange(progress*1000);
//     }
// 
//     public enum Status {
//         PLAYING, STOPPED, PAUSED
//     }
// }
// 
// Path: app/src/main/java/com/architjn/audiobook/interfaces/IPlayerService.java
// public interface IPlayerService {
//     void setSource(BookChapter audiobook);
// 
//     int play();
// 
//     void onSeekChange(int progress);
// }


import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.support.annotation.Nullable;
import com.architjn.audiobook.bean.BookChapter;
import com.architjn.audiobook.interactor.PlayerInteractor;
import com.architjn.audiobook.interfaces.IPlayerService;
import java.io.IOException;
import static com.architjn.audiobook.interactor.PlayerInteractor.Status.PAUSED;
import static com.architjn.audiobook.interactor.PlayerInteractor.Status.PLAYING;
package com.architjn.audiobook.service;





/**
 * Created by HP on 30-07-2017.
 */

public class PlayerService extends Service implements IPlayerService {

    private MediaPlayer mediaPlayer;
    private boolean gotContent;
    private PlayerInteractor interactor;

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        interactor = PlayerInteractor.getInstance(this);
        interactor.setServiceListener(this);
        mediaPlayer = new MediaPlayer();
        gotContent = false;
        return START_STICKY;
    }

    @Override
// Path: app/src/main/java/com/architjn/audiobook/bean/BookChapter.java
// public class BookChapter implements Serializable{
//     private String id;
//     private String title;
//     private long duration;
//     private String data;
//     private long currDuration;
// 
//     public BookChapter() {
//         //for serializable
//     }
// 
//     public BookChapter(String id, String title, long duration, String data, long currDuration) {
//         this.id = id;
//         this.title = title;
//         this.duration = duration;
//         this.data = data;
//         this.currDuration = currDuration;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public long getDuration() {
//         return duration;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public void setTitle(String title) {
//         this.title = title;
//     }
// 
//     public void setDuration(long duration) {
//         this.duration = duration;
//     }
// 
//     public String getData() {
//         return data;
//     }
// 
//     public void setData(String data) {
//         this.data = data;
//     }
// 
//     public long getCurrDuration() {
//         return currDuration;
//     }
// 
//     public void setCurrDuration(long currDuration) {
//         this.currDuration = currDuration;
//     }
// }
// 
// Path: app/src/main/java/com/architjn/audiobook/interactor/PlayerInteractor.java
// public class PlayerInteractor {
// 
//     private static PlayerInteractor instance;
// 
//     private final Context context;
//     private final DBHelper db;
//     private IPlayerPresenter presenter;
//     private IPlayerService service;
//     private Status status;
//     private AudioBook audiobook;
//     private int chapterNo = 0;
// 
//     public static PlayerInteractor getInstance(Context context) {
//         if (instance == null)
//             instance = new PlayerInteractor(context);
//         return instance;
//     }
// 
//     private PlayerInteractor(Context context) {
//         this.context = context;
//         this.db = DBHelper.getInstance(context);
//     }
// 
//     public void setPresenterListener(IPlayerPresenter presenter) {
//         this.presenter = presenter;
//     }
// 
//     public void setServiceListener(IPlayerService service) {
//         this.service = service;
//     }
// 
//     public AudioBook loadBook(String albumId) {
//         audiobook = db.getAudioBookViaId(albumId);
//         if (service != null && audiobook != null)
//             service.setSource(audiobook.getChapters().get(chapterNo));
//         return audiobook;
//     }
// 
//     public int playBook() {
//         if (service != null)
//             return service.play();
//         else return -1;
//     }
// 
//     public void setStatus(Status status) {
//         this.status = status;
//     }
// 
//     public Status getStatus() {
//         return status;
//     }
// 
//     public BookChapter getNextChapter() {
//         if (audiobook != null && audiobook.getChapters().size() > chapterNo)
//             return audiobook.getChapters().get(chapterNo);
//         else return null;
//     }
// 
//     public void askToPlay() {
//         presenter.playSong();
//     }
// 
//     public void updateSeek(int progress) {
//         if (service!=null)
//             service.onSeekChange(progress*1000);
//     }
// 
//     public enum Status {
//         PLAYING, STOPPED, PAUSED
//     }
// }
// 
// Path: app/src/main/java/com/architjn/audiobook/interfaces/IPlayerService.java
// public interface IPlayerService {
//     void setSource(BookChapter audiobook);
// 
//     int play();
// 
//     void onSeekChange(int progress);
// }


// Path: app/src/main/java/com/architjn/audiobook/service/PlayerService.java
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.support.annotation.Nullable;
import com.architjn.audiobook.bean.BookChapter;
import com.architjn.audiobook.interactor.PlayerInteractor;
import com.architjn.audiobook.interfaces.IPlayerService;
import java.io.IOException;
import static com.architjn.audiobook.interactor.PlayerInteractor.Status.PAUSED;
import static com.architjn.audiobook.interactor.PlayerInteractor.Status.PLAYING;

package com.architjn.audiobook.service;





/**
 * Created by HP on 30-07-2017.
 */

public class PlayerService extends Service implements IPlayerService {

    private MediaPlayer mediaPlayer;
    private boolean gotContent;
    private PlayerInteractor interactor;

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        interactor = PlayerInteractor.getInstance(this);
        interactor.setServiceListener(this);
        mediaPlayer = new MediaPlayer();
        gotContent = false;
        return START_STICKY;
    }

    @Override
    public void setSource(BookChapter chapter) {