Find out which Music is currently playing [Android]

徘徊边缘 提交于 2021-02-06 12:55:50

问题


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 ?


回答1:


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

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

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

Edit:

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

[Update]

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.



来源:https://stackoverflow.com/questions/22721667/find-out-which-music-is-currently-playing-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!