How to get the Information of the music track playing on an Android device?
I want to get the Information of the Music track 开发者_高级运维playing on an Android device. Is there any Android-powered API available for this? Or do I have to write a plugin for respective Android media players?
This is technically a hack. And works only with the Music App that comes bundled with Android.
Copy this IMediaPlaybackService.aidl into your Project...Refer this Post to access the MediaPlayer Service. You can then access all these functions.
package com.android.music;
import android.graphics.Bitmap;
interface IMediaPlaybackService
{
void openFile(String path, boolean oneShot);
void openFileAsync(String path);
void open(in long [] list, int position);
int getQueuePosition();
boolean isPlaying();
void stop();
void pause();
void play();
void prev();
void next();
long duration();
long position();
long seek(long pos);
String getTrackName();
String getAlbumName();
long getAlbumId();
String getArtistName();
long getArtistId();
void enqueue(in long [] list, int action);
long [] getQueue();
void moveQueueItem(int from, int to);
void setQueuePosition(int index);
String getPath();
long getAudioId();
void setShuffleMode(int shufflemode);
int getShuffleMode();
int removeTracks(int first, int last);
int removeTrack(long id);
void setRepeatMode(int repeatmode);
int getRepeatMode();
int getMediaMountedCount();
}
For other players, you'll need to check if they expose their service to other applications.
I'm new to Android and I don't know how this is done. But! I know that the last.fm Android app must do this, because it displays the info from the currently playing media player track, and "scrobbles" (sends a list of tracks you play in Android's media player to their site). And, I also know that their app is open source. The code is here: https://github.com/c99koder/lastfm-android/
So, if you have the time, you should be able to search through their code and figure out how they did it.
精彩评论