How to get the Information of the music track playing on an Android device?

前端 未结 2 1374
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-18 11:28

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 respec

2条回答
  •  甜味超标
    2020-12-18 12:21

    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.

提交回复
热议问题