获得在Android的当前播放的音频元 [英] Getting METADATA of currently played audio in Android
问题描述
我已经创建了一个应用程序来获取当前播放的音乐元数据mediaPlayBackService的Froyo的帮助。
I have created an application to get METADATA of currently played audio with the help of mediaPlayBackService in FROYO.
现在,当我在姜饼SDK导致崩溃的mediaPlayBackService尝试它是由当地的服务。
Now when I am trying it on GingerBread SDK it is crashing as mediaPlayBackService is made local service.
有没有办法通过它我可以用这个服务,或任何其他方式,我可以得到META为当前播放的音频绑定。
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.
谢谢
Swapnil
推荐答案
我发现了一个解决方案,以获得当前播放歌曲的元数据。
I found out one solution to get the METADATA of currently played song.
有关获取元数据,
-
创建一个意图过滤器与以下操作: PLAYSTATE_CHANGED META_CHANGED PLAYBACK_COMPLETE
Create a Intent filter with following Actions: PLAYSTATE_CHANGED META_CHANGED PLAYBACK_COMPLETE
注册我们的应用程序与上述的IntentFilter
Register our application with above IntentFilter
在的onReceive函数中,我们会得到包如下:
In onReceive function we will get the bundle as follows:
Bundle bundle = intent.getExtras();
这个包将包含新的/更改的元数据。我们可以得到的TrackID像
This bundle will contain the new/changed MetaData. We can get TrackID like
long trackId = (Long) bundle.get("id");
随着轨道ID的帮助下,我们可以查询数据库,让正在播放的音频文件的其他细节。 (我没有测试过,但同捆应该给音频文件的其他属性也是如此)
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.
谢谢, Swapnil
Thanks, Swapnil
这篇关于获得在Android的当前播放的音频元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!