找出当前正在播放的音乐[Android] [英] Find out which Music is currently playing [Android]

查看:137
本文介绍了找出当前正在播放的音乐[Android]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有办法找出android音乐播放器中当前正在播放的音乐?因此,我想捕捉标题时间,也许还想赶上这首音乐的作者,并用Textview展示它.这可能吗?

Is there a way to find out which music is currently playing in the android Music player ? So I want to catch the title time and maybe the author of this music and show it with Textview. Is this possible ?

推荐答案

与此处的Android API一致: AudioManager 应该是您想要的

In concordance with the Android API here: AudioManager should be what you are looking for

您可以创建一个 AudioManager ,然后调用 isMusicActive 来检索布尔值(如果正在播放).

You can create an AudioManager and then call the isMusicActive to retrieve a boolean if it is playing.

然后,您可以使用 MediaPlayer API并调用 getTrackInfo 方法,该方法返回与轨道相关的信息的 Array .

You can then use the MediaPlayer API and call the getTrackInfo method which returns an Array of track-related information.

此外, MediaPlayer 有一个 isPlaying 方法,在这种情况下,它确实使AudioManager变得毫无用处.

Also, MediaPlayer has an isPlaying method which really makes AudioManager rather useless in this scenario.

[更新]

供以后观看此问题的读者使用;创建 MediaPlayer 对象并调用 getTrackInfo 方法时;它返回一个数组 TrackInfo [] ; TrackInfo [] 的API及其方法也可以找到

For future viewers of this question; when you create a MediaPlayer object and call the getTrackInfo method; it returns an array TrackInfo[]; the API for TrackInfo[] and it's methods can also be found here.

这篇关于找出当前正在播放的音乐[Android]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆