3

I am trying to develop an application that gets metadata of other applications that are playing music / video. Right now, I am focusing on the Youtube Android app. I figured that MusixMatch does it, so it must be possible. From what I can gather, MusixMatch listens to any changes to the MediaSession of Youtube in order to retrieve metadata. My question is how?

Here's what I have tried done so far.

  1. Set up a MediaBrowserService.
  2. Set up callbacks on the MediaBrowserService
  3. Set up the token on the service.

But I'm still generally confused. The service should be able to be triggered in the back, even when the application has died. This means I do not manually bind the service to anything. So... How is it exactly being triggered? I tried adding intent-filters but the ones I have tried haven't worked.

Here is the list of intent-filters I have tried... I tried a bunch, because none were working.

 <receiver
        android:name=".broadcastReceiver.YoutubeReceiver"
        android:enabled="@bool/youtubeBroadcast"
        android:exported="@bool/youtubeBroadcast"
        tools:ignore="ExportedReceiver">
        <intent-filter>

             <action android:name="com.android.youtube.metachanged"/>
             <action android:name="com.google.android.youtube.onPlaybackStateChanged"/>
             <action android:name="com.google.android.youtube.onplaybackstatechanged"/>
             <action android:name="com.google.android.youtube.player.YouTubePlayer.OnInitializedListener"/>
             <action android:name="com.google.android.youtube.player.YouTubePlayer.PlaybackEventListener"/>
             <action android:name="com.google.android.youtube.player.YouTubePlayer.OnFullscreenListener"/>
             <action android:name="com.google.android.youtube.player.YouTubePlayer.PlayerStateChangeListener"/>

       </intent-filter>
</receiver>
Dan
  • 358
  • 2
  • 3
  • 17
  • Have you flagged your receiver android:exported="true"? You should write your whole receiver object from the manifest in the question and not just the actions – pantos27 Sep 27 '17 at 10:24
  • I don't think [that would be a problem](https://developer.android.com/guide/topics/manifest/receiver-element.html#exported), because android:exported=true by default – Dan Sep 27 '17 at 13:48
  • Awesome. Good luck then – pantos27 Sep 27 '17 at 13:53
  • @Dan , Any luck in getting metadata of media played by other apps? – Udayan Oct 26 '18 at 09:40

1 Answers1

0

I don't think that there is a way to do this. It would be quite a major security issue if this were possible, especially without obtaining any critical permission.

As for Musixmatch, I believe they're simply reading the notification title of your music app (that's what you give consent to upon the first run of the app) and then guessing the song being played. That's also the reason why lyrics aren't synchronized when the media is being played from another app.

EDIT: This might be worth a shot https://developer.android.com/reference/android/media/session/MediaSessionManager#addOnActiveSessionsChangedListener(android.media.session.MediaSessionManager.OnActiveSessionsChangedListener,%2520android.content.ComponentName)

johnny
  • 169
  • 1
  • 8
  • What you said in the edit is what they're using, it requires having the notification permission. – Steve M Jan 24 '21 at 22:23