Use .setDataSource to get mediaMetadata from currently playing music app

主宰稳场 提交于 2019-12-02 13:43:23

问题


I want to get MediaMetadata (song title / artist) from the current playing android audio source for any app (spotify, google play, soundcloud, YouTube, blackplayer, etc) and am trying to use MediaMetadataRetriever.setDatSource

Currently I have a function 'getActiveNotifications' in 'MainActivity.java' that gets called whenever a button is pressed, my code looks like this:

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. ");
}

Can I use .setDatSource generally for any music app or does it work for files only?

I can see updateMediaMetaData in Logcat printing media metadata of the currently playing song working for both music streaming and file playing apps (see pic)

Am I on the correct track here? Is there a way I can use .getDataSource on streaming / fileplayer apps for whatever the currently playing audio source is?

any help much appreciated, thanks

来源:https://stackoverflow.com/questions/55036223/use-setdatasource-to-get-mediametadata-from-currently-playing-music-app

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