我想从任何应用程序(spotify、google play、soundcloud、YouTube、blackplayer等)的当前播放android音频源获取MediaMetadata(歌曲标题/艺术家),并尝试使用我diaMetadataRetriever.setDatSource
目前我有一个函数'getActiveNotifications'在'MainActivity.java'每当按下按钮时都会调用,我的代码如下所示:
public void getActiveNotifications(View view) {
String temp ="temp";
Log.i("myTag", "Logging active notifications:");
//get data from MediaMetaData somehow? Always displays correct string in Logcat
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
//mmr.setDataSource("CURRENT APP PLAYING MUSIC (googlePlay / Spotify / Soundcloud etc)");
mmr.setDataSource("https://somewebsite.com/somefile.mp3", new HashMap<String,String>());
//extract metadata and save to string
String albumName = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
Log.i("myTag", "done with function. ");
}
我可以对任何音乐应用程序使用.setDatSource吗?还是它只对文件有效?
我可以在Logcat中看到UpdateDiametaData打印当前正在播放的歌曲的媒体元数据,用于音乐流和文件播放应用程序(见图)
我走对了吗?有没有一种方法可以在流媒体/文件播放器应用程序上使用.getDataSource来处理当前正在播放的音频源?
非常感谢您的帮助,谢谢