什么是" ID"在Android&QUOT领域,谷歌播放音乐和QUOT;广播意图对应? [英] What does the "id" field in an Android "Google Play Music" broadcast intent correspond to?

查看:352
本文介绍了什么是" ID"在Android&QUOT领域,谷歌播放音乐和QUOT;广播意图对应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一款Android应用,听音乐广播。它接收使用以下ApplicationManifest.xml(片段),曲目变化通知:

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>

当我从我的Nexus 4运行默认(内置)的谷歌播放音乐应用得到这个广播意图,捆绑有大约当前播放的曲目有用信息,包括艺术家和称号 。它的的有一个文件路径,我想。但它确实有一个id字段(),这让我觉得我也许可以查找使用该ID作为一个关键的附加信息。但我想不通:内容提供商是什么数据库/这个ID钥匙插入

When I get this broadcast intent from my nexus 4 running the default (builtin) Google Play Music app, the bundle has useful information about the currently playing track, including "artist" and "title". It doesn't 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?

事情到目前为止,我已经试过:

Things I've tried so far:

1)我本来期望这对应于内容解析器的_ID领域之一:

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


  • MediaStore.Audio.Media.INTERNAL_CONTENT_URI

  • MediaStore.Audio.Media.EXTERNAL_CONTENT_URI

不过,我已经试过查询这两个,而ID是无处同一个球场。我现在的例子是,我发现了一个的ID(在广播) 3399 。但在EXTERNAL_CONTENT_URI查询所有曲目给我的ID在20865-23051的范围内,加上一对小的ID(20和24,对应于由谷歌+应用程式安装通知和铃声)。

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).

有关这个来源,为当前播放曲目的ID是 21373 (我抬头依据的路径,我可以通过人工检查找出上的ID)

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只是给我的东西内置(如铃声等) - 所有的ID都是&LT; 100,所以这是没有用的不是。

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

2)我没有对相同的查询的所有的媒体对象 - 使用 MediaStore.Files.getContentUri(外部)。我回来了很多成果,但ID 3399 是newsrob(RSS阅读器)缓存,所以这显然不相关的随机文件。

2) I did the same query against all 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.

推荐答案

在MediaPlaybackService.java源$ C ​​$ C请看下图:

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;
}

有些code有关的ContentProvider:

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.

这篇关于什么是&QUOT; ID&QUOT;在Android&QUOT领域,谷歌播放音乐和QUOT;广播意图对应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆