Android Open Source - AStory Custom Media Player






From Project

Back to project page AStory.

License

The source code is released under:

Apache License

If you think the Android project AStory listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.Litterfeldt.AStory.customClasses;
import android.media.MediaPlayer;
//  w  w w.  j a  v  a2s .c o m
import com.Litterfeldt.AStory.models.Book;
import java.io.IOException;

public class CustomMediaPlayer {
    private MediaPlayer mp;
    private Book currentBook;
    private boolean backgroundToggle;
    public void setBackgroundToggle(boolean b){
        backgroundToggle = b;
    }
    public boolean getBackgroundToggle(){
        return backgroundToggle;
    }

    public CustomMediaPlayer(){
        mp = new MediaPlayer();
    }
    public void playBook(Book book,int chapterIndex){
        try{
            currentBook = book;
            setBackgroundToggle(false);
            stop();
            reset();
            setDataSource(book.getChapter(chapterIndex).Path());
            prepare();
            start();
        }catch(IOException e){
            currentBook = null;
        }
    }

    public boolean nextChapter(){
        if (hasBook() && currentBook.hasNextChapter()) {
            try {
                stop();
                reset();
                setDataSource(currentBook.nextChapter().Path());
                prepare();
                start();
                return true;
            }catch (IOException e){
                currentBook = null;
            }catch (NullPointerException e){
                currentBook = null;
            }
        }
        return false;
    }
    public boolean previousChapter(){
        if (hasBook() && currentBook.hasPreviousChapter()) {
            try {
                stop();
                reset();
                setDataSource(currentBook.prevChapter().Path());
                prepare();
                start();
                return true;
            }catch (IOException e){
                currentBook = null;
            }
        }
        return false;
    }
    public void setOnCompletionListener( MediaPlayer.OnCompletionListener listener ){
        mp.setOnCompletionListener(listener);
    }
    public int getCurrentPosition(){
        return hasBook() ? mp.getCurrentPosition() : 0;
    }
    public int getDuration(){
        return hasBook() ? mp.getDuration() : 0;
    }
    public void seekTo(int i){
        if (hasBook()) mp.seekTo(i);
    }
    public void start(){
        if (hasBook()) mp.start();
    }
    public void pause(){
        if (hasBook()) mp.pause();
    }
    public void reset(){
        if (hasBook()) mp.reset();
    }
    public void setDataSource(String dataSource) throws IOException {
        mp.setDataSource(dataSource);
    }
    public void prepare() throws IOException {
        mp.prepare();
    }
    public void stop(){
        if (hasBook()) mp.stop();
    }
    public void release(){
        mp.release();
    }
    public boolean hasBook(){
        return (currentBook != null);
    }
    public boolean isPlaying(){
        return mp.isPlaying();
    }
    public int currentChapterIndex(){
        return currentBook.currentChapterIndex();
    }
    public Book book(){
        return currentBook;
    }
    public void removeBook(){
        currentBook = null;
    }
}




Java Source Code List

com.Litterfeldt.AStory.adapters.LibraryAdapter.java
com.Litterfeldt.AStory.customClasses.CoreApplication.java
com.Litterfeldt.AStory.customClasses.CustomMediaPlayer.java
com.Litterfeldt.AStory.dbConnector.dbBook.java
com.Litterfeldt.AStory.dbConnector.dbConnector.java
com.Litterfeldt.AStory.dbConnector.dbSave.java
com.Litterfeldt.AStory.fragments.LibraryFragment.java
com.Litterfeldt.AStory.fragments.PlayerFragment.java
com.Litterfeldt.AStory.models.Book.java
com.Litterfeldt.AStory.models.Chapter.java
com.Litterfeldt.AStory.models.FileSystem.java
com.Litterfeldt.AStory.models.SaveState.java
com.Litterfeldt.AStory.services.AudioplayerService.java
com.Litterfeldt.AStory.pagerView.java
com.handmark.pulltorefresh.library.ILoadingLayout.java
com.handmark.pulltorefresh.library.IPullToRefresh.java
com.handmark.pulltorefresh.library.LoadingLayoutProxy.java
com.handmark.pulltorefresh.library.OverscrollHelper.java
com.handmark.pulltorefresh.library.PullToRefreshAdapterViewBase.java
com.handmark.pulltorefresh.library.PullToRefreshBase.java
com.handmark.pulltorefresh.library.PullToRefreshExpandableListView.java
com.handmark.pulltorefresh.library.PullToRefreshGridView.java
com.handmark.pulltorefresh.library.PullToRefreshHorizontalScrollView.java
com.handmark.pulltorefresh.library.PullToRefreshListView.java
com.handmark.pulltorefresh.library.PullToRefreshScrollView.java
com.handmark.pulltorefresh.library.PullToRefreshWebView.java
com.handmark.pulltorefresh.library.extras.PullToRefreshWebView2.java
com.handmark.pulltorefresh.library.extras.SoundPullEventListener.java
com.handmark.pulltorefresh.library.internal.EmptyViewMethodAccessor.java
com.handmark.pulltorefresh.library.internal.FlipLoadingLayout.java
com.handmark.pulltorefresh.library.internal.IndicatorLayout.java
com.handmark.pulltorefresh.library.internal.LoadingLayout.java
com.handmark.pulltorefresh.library.internal.RotateLoadingLayout.java
com.handmark.pulltorefresh.library.internal.Utils.java
com.handmark.pulltorefresh.library.internal.ViewCompat.java