Java 无法获取歌曲的专辑艺术

Java 无法获取歌曲的专辑艺术,java,android,xml,user-interface,layout,Java,Android,Xml,User Interface,Layout,我是android应用程序开发的新手。我想为音乐播放器中播放的每首歌曲添加封面艺术或专辑艺术。我已经尝试了许多从堆栈溢出读取的方法,但没有一种对我有效。我似乎缺少一些基本的概念。我犯了一个错误。我不知道如何消除这个错误。我犯了一个错误 getAlbumart(songs); 它说无法解析符号歌曲 有人能帮我吗 这是密码 public void abc(){ mMediaPlayer = new MediaPlayer(); setContentVie

我是android应用程序开发的新手。我想为音乐播放器中播放的每首歌曲添加封面艺术或专辑艺术。我已经尝试了许多从堆栈溢出读取的方法,但没有一种对我有效。我似乎缺少一些基本的概念。我犯了一个错误。我不知道如何消除这个错误。我犯了一个错误

getAlbumart(songs);  
它说无法解析符号歌曲

有人能帮我吗

这是密码

    public void abc(){
        mMediaPlayer = new MediaPlayer();
        setContentView(R.layout.playlist);

        ListView mListView = (ListView) findViewById(R.id.list);

        mMusicList = getAudioList();

        ArrayAdapter<String> mAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, mMusicList);
        mListView.setAdapter(mAdapter);

        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {

                try {


                    playSong(mAudioPath[arg2]);
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalStateException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    private String[] getAudioList() {
        final Cursor mCursor = getContentResolver().query(
                MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                new String[]{MediaStore.Audio.Media.DISPLAY_NAME, MediaStore.Audio.Media.DATA}, null, null,
                "LOWER(" + MediaStore.Audio.Media.TITLE + ") ASC");

        int count = mCursor.getCount();

        String[] songs = new String[count];
        mAudioPath = new String[count];
        int i = 0;
        if (mCursor.moveToFirst()) {
            do {
                songs[i] = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME));
                mAudioPath[i] = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
                i++;
            } while (mCursor.moveToNext());
        }

        mCursor.close();
        return songs;
    }

    private void playSong(String path) throws IllegalArgumentException,
            IllegalStateException, IOException {
        setContentView(R.layout.activity_audio_player);


        Log.d("ringtone", "playSong :: " + path);

        mMediaPlayer.reset();
        mMediaPlayer.setDataSource(path);
        mMediaPlayer.prepare();
        mMediaPlayer.start();


        getAlbumart(songs);

    }
    public Bitmap getAlbumart(Long album_id)
    {
        Bitmap bm = null;
        try
        {
            final Uri sArtworkUri = Uri
                    .parse("content://media/external/audio/albumart");

            Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
            ParcelFileDescriptor pfd =  Bacon1.this.getContentResolver().openFileDescriptor(uri, "r");

            if (pfd != null)
            {
                FileDescriptor fd = pfd.getFileDescriptor();
                bm = BitmapFactory.decodeFileDescriptor(fd);
            }
        } catch (Exception e) {
        }
        return bm;
    }

}
public void abc(){
mMediaPlayer=新媒体播放器();
setContentView(R.layout.playlist);
ListView mListView=(ListView)findViewById(R.id.list);
mMusicList=getAudioList();
ArrayAdapter mAdapter=新的ArrayAdapter(此,
android.R.layout.simple_list_item_1,mMusicList);
mListView.setAdapter(mAdapter);
mListView.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
公共链接(AdapterView arg0、视图arg1、内部arg2、,
长arg3){
试一试{
playSong(mAudioPath[arg2]);
}捕获(IllegalArgumentException e){
e、 printStackTrace();
}捕获(非法状态){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}
}
});
}
私有字符串[]getAudioList(){
最终游标mCursor=getContentResolver().query(
MediaStore.Audio.Media.EXTERNAL\u CONTENT\u URI,
新字符串[]{MediaStore.Audio.Media.DISPLAY_NAME,MediaStore.Audio.Media.DATA},null,null,
“下(“+MediaStore.Audio.Media.TITLE+”)ASC”);
int count=mCursor.getCount();
字符串[]歌曲=新字符串[计数];
mAudioPath=新字符串[计数];
int i=0;
if(mCursor.moveToFirst()){
做{
songs[i]=mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME));
mAudioPath[i]=mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
i++;
}while(mCursor.moveToNext());
}
mCursor.close();
返回歌曲;
}
私有void playSong(字符串路径)抛出IllegalArgumentException,
IlegalStateException,IOException{
setContentView(R.layout.activity\u audio\u player);
Log.d(“铃声”,“播放歌曲::”+path);
mmediplayer.reset();
mmediplayer.setDataSource(路径);
mmediplayer.prepare();
mmediplayer.start();
艺术(歌曲);
}
公共位图getAlbumart(长相册\u id)
{
位图bm=null;
尝试
{
最终Uri sArtworkUri=Uri
.parse(“content://media/external/audio/albumart");
Uri=ContentUris.withAppendedId(sArtworkUri,唱片集id);
ParcelFileDescriptor pfd=Bacon1.this.getContentResolver().openFileDescriptor(uri,“r”);
如果(pfd!=null)
{
FileDescriptor fd=pfd.getFileDescriptor();
bm=BitmapFactory.decodeFileDescriptor(fd);
}
}捕获(例外e){
}
返回bm;
}
}

我认为
歌曲
可能为空或未设置。我在《私人void playSong》中看不到任何参考资料你能帮助我如何获得歌曲的专辑艺术吗?在我的应用程序中,其他一切正常。我如何设置歌曲?我认为
songs
可能为空或未设置。我在《私人void playSong》中看不到任何参考资料你能帮助我如何获得歌曲的专辑艺术吗?在我的应用程序中,其他一切都正常工作我如何设置歌曲?