49563

What does the “id” field in an Android “Google Play Music” broadcast intent correspond to?

Question:

I've got an android app that listens to music broadcasts. It receives track change notifications using the following ApplicationManifest.xml (snippet):

<receiver android:name=".music.AndroidMusicBroadcastReceiver"> <intent-filter> <action android:name="com.android.music.metachanged"/> <action android:name="com.android.music.playbackcomplete"/> <action android:name="com.android.music.playstatechanged"/> <action android:name="com.htc.music.metachanged"/> <action android:name="com.htc.music.playbackcomplete"/> <action android:name="com.htc.music.playstatechanged"/> </intent-filter> </receiver>

When I get this broadcast intent from my nexus 4 running the default (builtin) <strong>Google Play Music</strong> app, the bundle has useful information about the currently playing track, including "artist" and "title". It <em>doesn't</em> have a file path, which I would like. But it does have an "id" field (a long), which makes me think I can perhaps look up the additional information using that ID as a key. But I can't figure out: What database / content provider is this ID a key into?

<hr />

Things I've tried so far:

1) I would have expected this to correspond to the _ID field of the content resolver for one of:

<ul><li>MediaStore.Audio.Media.INTERNAL_CONTENT_URI</li> <li>MediaStore.Audio.Media.EXTERNAL_CONTENT_URI</li> </ul>

But I've tried querying both of those, and the IDs are nowhere in the same ballpark. My current example is that I'm getting an "id" (in the broadcast) of 3399. But querying all the tracks in the EXTERNAL_CONTENT_URI gives me IDs in the range of 20865-23051, plus a couple of small IDs (20 and 24, corresponding to a notification and ringtone installed by the google+ app).

For this source, the ID for the currently playing track would be 21373 (I looked up the ID based on the path, which I can figure out by manual inspection).

INTERNAL_CONTENT_URI just gives me builtin stuff (like ringtones, etc) - all the IDs are < 100, so that's not useful either.

2) I did the same query against <em>all</em> media objects - using MediaStore.Files.getContentUri("external"). I got back plenty of results, but ID 3399 is a random file cached by newsrob (an RSS reader), so that's clearly not relevant.

Answer1:

Take a look at the source code in MediaPlaybackService.java:

private void notifyChange(String what) { Intent i = new Intent(what); i.putExtra("id", Long.valueOf(getAudioId())); i.putExtra("artist", getArtistName()); i.putExtra("album",getAlbumName()); i.putExtra("track", getTrackName()); i.putExtra("playing", isPlaying()); ... } /** * Returns the rowid of the currently playing file, or -1 if * no file is currently playing. */ public long getAudioId() { synchronized (this) { if (mPlayPos >= 0 && mPlayer.isInitialized()) { return mPlayList[mPlayPos]; } } return -1; }

Some code about the ContentProvider:

Cursor crsr = MusicUtils.query(this, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String [] {"_id"}, "_id=" + mPlayList[mPlayPos] , null, null);

I think I don't need to say something else. :) Hope this can help you.

Recommend

  • How to delete an Analytics Event from Firebase
  • How to use vowpal wabbit for online prediction (streaming mode)
  • Setting jCheckBox invisible in jTable
  • Was default_marker removed from mapbox-gl.js
  • How to set title name of the pdf. While viewing the Document(New Tab)
  • Storyboard iOS MBProgressHUD
  • How to add CKEditor RTE to typo3 Backend Module with the API?
  • How to create 2 svg's on one page?
  • How do I detect if an email client is configured on an Android device?
  • Display standard razor/mvc 3 validation messages displayed in another language
  • QNetworkAccessManager one instance and connecting slots
  • Validating a Firebase Key [duplicate]
  • Jekyll - How do I create pages in the root directory?
  • Javascript / jQuery not executing in IE until the body of the page is moused over
  • Calling a flash ExternalInterface in swiffyobject
  • android : speech recognition what are the technologies available
  • Loading hyperspectral images in Octave
  • jQuery Ajax call to WCF service returning “Method not allowed (405)”
  • Load php page results into div with ajax with link?
  • Delete a ListItem by clicking the ImageView within the ListItem
  • GTK3 + OpenGL for windows: multiple GtkGLArea (ie. OpenGL contexts)
  • .Net core Hosted Services guaranteed to complete
  • opencv deskewing a contour
  • How to define a custom accuracy in Keras to ignore samples with a particular gold label?
  • Java Collections.shuffle() weird behaviour [closed]
  • Annotate objects in a queryset with next and previous object ids
  • Calculate time from document
  • Unable to create Access token grant type in wso2 API manager store to test API
  • 'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs
  • how do i compare two rows and store the similarities of the two rows in another column
  • Amazon Elastick BeanStalk error: Failed to create the AWS Elastic Beanstalk application version
  • how to run ejabberd with Erlang on Heroku?
  • How to specify generic type when the type is only known at runtime?
  • How do I add a mouse over tooltip to an Image using .DrawImage()
  • matrix multiplication apache pig
  • Functions by reference or by variable, which to use when?
  • Sign a Pdf using custom digital signature in Java
  • multiple button click in asp.net MVC 3
  • Jersey serializes character value to ASCII equivalent numeric string
  • Running R's aov() mixed effects model from Python using rpy2