2013-03-11 22 views
0

我有filebrowser上市SD卡上的所有視頻由i want get audio files in sd card的Android ContentResolver.query總是返回相同的數據

使用ContentResolver的啓發

代碼錄像機的應用程序,工作正常,但它不會,如果文件更新換卡。我不是自動的,而是在查看/應用程序重新啓動後。甚至沒有重新安裝應用程序幫助,仍然顯示相同的文件。已刪除的視頻文件無法通過PC顯示,也無法播放(此視頻無法播放(翻譯))。

我傾銷了數據,問題不在視圖緩存或其他地方。我沒有執行任何我自己的緩存,也沒有找到有關此事的任何信息。謝謝

代碼:

// acquisition 
    String[] projection = { 
     MediaStore.Video.Media._ID, 
     MediaStore.Video.Media.DISPLAY_NAME, 
     MediaStore.Video.Media.DURATION, 
     MediaStore.Video.Media.DATA 
    }; 

    ContentResolver resolver = getActivity().getContentResolver(); 
    Cursor videoCursor = resolver.query(
     MediaStore.Video.Media.EXTERNAL_CONTENT_URI, 
     projection, 
     null, 
     null, 
     null 
    ); 

    // extraction 
    while(cursor.moveToNext()) { 
     cursorIndex = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); 
     filepath = cursor.getString(cursorIndex); 

     cursorIndex = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME); 
     filename = cursor.getString(cursorIndex); 

     cursorIndex = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION); 
     duration = cursor.getString(cursorIndex); 

     result[ index++ ] = new VideoFileMetadata(filename, duration, filepath); 
    } 

編輯1 [14-03-2013]:

我嘗試添加number + " = " + number訂購或WHERE子句作爲一個潛在的查詢緩存剋星,但它有沒有效果(儘管它可能被優化器作爲無用的子句刪除)。這次我使用不同的證書從不同的機器重新安裝了應用程序,但查詢結果保持不變,列出了當前不存在的文件。

+0

順便說一句,MediaStore.Video.Media.DURATION不受MediaStore自動計算的,因此通常爲0,除非另一個應用程序與更新MediaStore數據庫記錄有效的價值。 – 2013-04-10 08:22:51

+0

謝謝,我會記住它...和代碼。我到目前爲止所嘗試的每個文件都有正確填充 – NoxArt 2013-04-10 14:53:33

回答

4

您應該先致電cursor.moveToFirst()

所以,你的光標迭代循環應該像

if (cursor.moveToFirst()) { 
    do { 
     // cursorIndex = cursor.getColumnIndexOrThrow, etc... 
    } while (cursor.moveToNext()); 
} 
+0

謝謝,我會盡力讓你知道它是如何實現的。 – NoxArt 2013-04-10 14:55:06

+0

它現在工作正常,所以我認爲它解決了它......謝謝! – NoxArt 2013-04-30 17:53:53

相關問題