Created
March 5, 2011 10:59
-
-
Save sudar/856293 to your computer and use it in GitHub Desktop.
Finding the currently playing song in Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* The service connection class that allows you to talk to the MediaPlayer Service | |
* | |
* @author "Sudar Muthu (http://sudarmuthu.com)" | |
* | |
*/ | |
private class MediaPlayerServiceConnection implements ServiceConnection { | |
public com.htc.music.IMediaPlaybackService mServiceHtc; | |
public com.android.music.IMediaPlaybackService mServiceAndroid; | |
@Override | |
public void onServiceConnected(ComponentName name, IBinder service) { | |
Log.i("MediaPlayerServiceConnection", "Connected! Name: " + name.getClassName()); | |
// This is the important line where we bind the service | |
if (isHtc) | |
mServiceHtc = com.htc.music.IMediaPlaybackService.Stub.asInterface(service); | |
else | |
mServiceAndroid = com.android.music.IMediaPlaybackService.Stub.asInterface(service); | |
} | |
/** | |
* Selects the next song | |
* | |
* @throws RemoteException | |
* | |
*/ | |
public void nextSong() throws RemoteException { | |
if (isHtc) { | |
mServiceHtc.next(); | |
} else { | |
mServiceAndroid.next(); | |
} | |
} | |
/** | |
* Selects the Previous song | |
* | |
* @throws RemoteException | |
*/ | |
public void prevSong() throws RemoteException { | |
if (isHtc) { | |
mServiceHtc.prev(); | |
} else { | |
mServiceAndroid.prev(); | |
} | |
} | |
@Override | |
public void onServiceDisconnected(ComponentName name) { | |
Log.i("MediaPlayerServiceConnection", "Disconnected!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment