简体   繁体   English

在Android中使用给定的Audio_id播放歌曲

[英]Play a song with given Audio_id in android

I am trying to get a song from a playlist then play it in android. 我正在尝试从播放列表中获取歌曲,然后在android中播放。

All answers i can find relies on 我能找到的所有答案都取决于

MediaStore.MediaColumn.DATA

to find the file path and then feed it to the MediaPlayer. 查找文件路径,然后将其提供给MediaPlayer。

But when i tried to do it, i kept getting "invalid column _data" exception.I can still query for other stuff about the song, like the "AUDIO_ID". 但是当我尝试执行此操作时,我一直收到“无效列_data”异常。我仍然可以查询有关歌曲的其他内容,例如“ AUDIO_ID”。 So my question is, is it possible to play the song with only the "AUDIO_ID" known? 所以我的问题是,是否可以仅使用“ AUDIO_ID”来播放歌曲? How? 怎么样? Or is there something that i am missing for the "data", since every other people are able to use it. 还是我缺少“数据”,因为其他所有人都可以使用它。

This is my code for getting playlist. 这是我获取播放列表的代码。

private Cursor getPlaylistCursor() {
    String[] proj = { MediaStore.Audio.Playlists._ID,MediaStore.Audio.Playlists.NAME };
    Uri playlistUri = Uri.parse("content://com.google.android.music.MusicConten/playlists");
    Cursor playlistCursor = getContentResolver().query(playlistUri, proj,null, null, null);
    playlistCursor.moveToFirst();
    return playlistCursor;
}

This is what i am working on for getting song, as i said, i cannot query the "data", if the "data" argument is added to the projection, i get an exception. 正如我所说的,这就是我正在努力获取的歌曲,我无法查询“数据”,如果将“数据”参数添加到投影中,则会出现异常。

private void getSongListCursor(Long playlistID) {
    String[] proj2 = { MediaStore.Audio.Playlists.Members.TITLE,
            MediaStore.Audio.Playlists.Members.AUDIO_ID };
    String playListRef = "content://com.google.android.music.MusicContent/playlists/"
            + playlistID + "/members";
    Uri songUri = Uri.parse(playListRef);
    Cursor songCursor = getContentResolver().query(songUri, proj2, null,
            null, null);
}

SO now, i have the audio ID of a song, how do i play it? 所以现在,我有了一首歌曲的音频ID,该如何播放?

Everything is possible ;-) 一切皆有可能 ;-)

My approach is to use the Google Play Music server to obtain the streaming URL corresponding to the selected song ID. 我的方法是使用Google Play音乐服务器获取与所选歌曲ID对应的流URL。 Just let me know if you need help with authentication and jump-start with the unofficial API for Google Play Music. 请告诉我是否需要身份验证方面的帮助,并开始使用非官方的Google Play音乐API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM