开发者

Getting METADATA of currently played audio in Android

开发者 https://www.devze.com 2023-04-10 21:00 出处:网络
I have created an appl开发者_JAVA技巧ication to get METADATA of currently played audio with the help of mediaPlayBackService in FROYO.

I have created an appl开发者_JAVA技巧ication to get METADATA of currently played audio with the help of mediaPlayBackService in FROYO.

Now when I am trying it on GingerBread SDK it is crashing as mediaPlayBackService is made local service.

Is there any way by which I can bind with this service or any other way by which I can get META for currently played Audio.

Thanks,

Swapnil


I found out one solution to get the METADATA of currently played song.

For getting metadata,

  1. Create a Intent filter with following Actions: PLAYSTATE_CHANGED META_CHANGED PLAYBACK_COMPLETE

  2. Register our application with above IntentFilter

  3. In onReceive function we will get the bundle as follows:

    Bundle bundle = intent.getExtras();
    
  4. This bundle will contain the new/changed MetaData. We can get TrackID like

    long  trackId = (Long) bundle.get("id");
    
  5. With the help of track ID we can query the database and get other details of Audio file being played. (I have not tested but the same bundle should give other properties of audio file too)

Only problem is that, if the audio file is already being played (i.e. before starting our application), we will not get any broadcast on start of our application and hence NO MetaData is available, on next audio change we will get the updated values.

Hope this help all who all looking for same stuff.

Thanks, Swapnil

0

精彩评论

暂无评论...
验证码 换一张
取 消