开发者

Cannot map BpMemoryHeap to Heap in android while media scanning

I want to scan all the songs present in the sdcard and show them on the list.

At present my approach is :-

  1. Create an asyncTask class
  2. In doInBackground method scan all the media files
  3. In post execute get ListView and setCursorAdapter to this ListView

In my Custom Cursor adapter i have 3 methods :- 4. BindView 5. newView 6. getView (Where i have onItemClickListener )

I have two issues here :- When i have songs more than 450 it doesnt scans all the songs and shows still 450 list items

The OnClickListener brings the Error -> Cannot map BpMemoryHeap to Heap. 07-18 18:00:56.977: ERROR/JavaBinder(1620): Uncaught remote exception! (Exceptions are not yet supported across processes.) *

The Following is my Async Task :-

private class FetchAllMusic extends AsyncTask { ArrayList tracks; Cursor cursor,cursorAlbums;

    @Override
    protected void onPreExecute() {
        myWaitDialog.run();
        super.onPreExecute();
    }

    @SuppressWarnings("unchecked")
    @Override
    protected Byte doInBackground(Void... params) {
            String[] projection = { MediaStore.Audio.Media._ID,
                MediaStore.Audio.Media.ARTIST,          MediaStore.Audio.Media.DATA,
                MediaStore.Audio.Media.DISPLAY_NAME,
                MediaStore.Audio.Media.DURATION, MediaStore.Audio.Media.ALBUM,
                MediaStore.Audio.Media.ALBUM_ID, MediaStore.Audio.Media.DURATION
                                 };
        String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
     cursor = PlaylistScreen.this.managedQuery(
                MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection,
                selection, null, null);
        cursor.m开发者_StackOverflowoveToFirst();

          cursorAlbums = null;
            if(cursor.moveToFirst()){
                do{
                 String[] projection1 = { MediaStore.Audio.Albums.ALBUM_ART };
                    String selection1 = MediaStore.Audio.Albums._ID + " =="
                            + cursor.getString(6);

                     cursorAlbums = PlaylistScreen.this.managedQuery(
                             MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, /* projection */
            projection1, selection1, null, null);

                }while(cursor.moveToNext());
            }

            return null;
    }

     protected void onPostExecute(Byte result) {

        myWaitDialog.dismiss();
        layoutAllMusic = (LinearLayout) findViewById(R.id.l_all_music);
        try{
        Comparator comparator = Collections.reverseOrder();
            System.out.println(tracks);
                //Collections.sort(tracks, comparator);
                }catch(Exception e){

            e.printStackTrace();
        }
    Log.d("Before List Adapter","+++++++++++++++++");
      PlaylistScreen.this.lv = getListView();


    MusicCursorAdapter musicCursor = new MusicCursorAdapter(PlaylistScreen.this, cursor, cursorAlbums);
       PlaylistScreen.this.lv.setAdapter(musicCursor);
      super.onPostExecute(result);
    }
}


Make sure you close all your cursors used....

cursor = PlaylistScreen.this.managedQuery(
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection,
            selection, null, null);
    cursor.moveToFirst();

      cursorAlbums = null;
        if(cursor.moveToFirst()){
            do{
             String[] projection1 = { MediaStore.Audio.Albums.ALBUM_ART };
                String selection1 = MediaStore.Audio.Albums._ID + " =="
                        + cursor.getString(6);

                 cursorAlbums = PlaylistScreen.this.managedQuery(
                         MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, /* projection */
        projection1, selection1, null, null);

            }while(cursor.moveToNext());
        }
        cursor.close();
        return null;

And again try closing the other two cursors(musicCursor, cursorAlbums) also. Hope it should work fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜