2

我想从任何应用程序(spotify、google play、soundcloud、YouTube、blackplayer 等)的当前播放的 android 音频源中获取 MediaMetadata(歌曲标题/艺术家),并尝试使用 MediaMetadataRetriever.setDatSource

目前我在“MainActivity.java”中有一个函数“getActiveNotifications”,每当按下按钮时都会调用它,我的代码如下所示:

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 中看到 updateMediaMetaData 打印当前播放歌曲的媒体元数据,适用于音乐流媒体和文件播放应用程序(见图)

在此处输入图像描述

我在正确的轨道上吗?有没有办法可以在流/文件播放器应用程序上使用 .getDataSource 来处理当前正在播放的音频源?

非常感谢任何帮助,谢谢

4

0 回答 0