Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: 3312116a83
Fetching contributors…

Cannot retrieve contributors at this time

111 lines (80 sloc) 3.307 kB


Let's call it a library? For working with audio playback in Android. 2.2+ only, kthx.


Basically, you should do the following:


class MyApplicationActivity extends Activity {

    private PlayerHater mPlayerHater;

    private ServiceConnection mConnection = new ServiceConnection() {

        public void onServiceConnected(ComponentName name, IBinder service) {
            mPlayerHater = (PlayerHater)service;

        public void onServiceDisconnected(ComponentName name) {
            mPlayerHater = null;

    public void onStart() {
        if (mPlayerHater == null) {
            Intent playerHaterIntent = new Intent(this, PlaybackService.class);
            Context context = getApplicationContext();

            context.bindService(playerHaterIntent, mConnection, Context.BIND_AUTO_CREATE);



Ok, so the way it works is this

├──        // Implements the state machine for Android's MediaPlayer class.
├──   // An interface you should implement
├──               // An interface that PlayerHaterBinder implements
├──         // Your main interaction point with PlayerHater
├──        // The workhorse
├──     // Handles maintaining MediaPlayer event listeners between sessions
└──    // Handles updating the scrubber/duration indicator.

If you want to build your own extensions to the library, here's how you do it for now:

  • Build a new interface which extends PlayerHater and adds any methods you want.
  • Extend PlayerHaterBinder and implement the interface you just created.
  • Extend PlaybackService to add the actual functionality/persistence (Binders are disposable)
  • Cast the binder you got back with the interface you created.
  • ???
  • Profit!

    The Interface:

    Basically, this should answer your questions.

    void seekTo(int position);
    boolean pause();
    boolean stop();
    boolean play();
    boolean play(String fileOrUrl);
    boolean play(String fileOrUrl, boolean isUrl);
    boolean play(String fileOrUrl, boolean isUrl, Activity activity);
    boolean play(String fileOrUrl, boolean isUrl, Activity activity, int view);
    boolean play(FileDescriptor fd);
    boolean play(FileDescriptor fd, Activity activity);
    boolean play(FileDescriptor fd, Activity activity, int view);
    boolean play(Uri url);
    boolean play(Uri url, Activity activity);
    boolean play(Uri url, Activity activity, int view);
    void setNotificationIntentActivity(Activity activity);
    void setNotificationView(int notificationView);
    int getCurrentPosition();
    void setOnBufferingUpdateListener(OnBufferingUpdateListener listener);
    void setOnCompletionListener(OnCompletionListener listener);
    void setOnInfoListener(OnInfoListener listener);
    void setOnSeekCompleteListener(OnSeekCompleteListener listener);
    void setOnErrorListener(OnErrorListener listener);
    void setOnPreparedListener(OnPreparedListener listener);
    void setOnProgressChangeListener(OnSeekBarChangeListener listener);
    String getNowPlaying();
    boolean isPlaying();
    int getState();
Jump to Line
Something went wrong with that request. Please try again.