Hi Caesar, Adding _ID to your projection will solve it ! The _ID column is expected by the way you use SimpleCursorAdapter.
Cheers, Horia On Feb 25, 5:52 am, Caesar <ntk0...@hotmail.com> wrote: > Hello, > > I`d like to implememt media list for SoundRecorder which is open_src > app. > > But I`ve found some Runtime error. > > I`ve insert media file into the MediaStore.Audio.Media using > 'addToMediaDB(File file)' > > =============================================================== > > private Uri addToMediaDB(File file) { > Resources res = getResources(); > ContentValues cv = new ContentValues(); > long current = System.currentTimeMillis(); > long modDate = file.lastModified(); > Date date = new Date(current); > SimpleDateFormat formatter = new SimpleDateFormat( > res.getString(R.string.audio_db_title_format)); > String title = formatter.format(date); > > // Lets label the recorded audio file as NON-MUSIC so that the > file > // won't be displayed automatically, except for in the > playlist. > cv.put(MediaStore.Audio.Media.IS_MUSIC, "0"); > > cv.put(MediaStore.Audio.Media.TITLE, title); > Log.d(MediaStore.Audio.Media.TRACK.toString > (),MediaStore.Audio.Media.TRACK.toString()); > cv.put(MediaStore.Audio.Media.DATA, file.getAbsolutePath()); > cv.put(MediaStore.Audio.Media.DATE_ADDED, (int) (current / > 1000)); > cv.put(MediaStore.Audio.Media.DATE_MODIFIED, (int) (modDate / > 1000)); > // cv.put(MediaStore.Audio.MediaColumns.DURATION, > mRecordingLength); > cv.put(MediaStore.Audio.Media.MIME_TYPE, MIME_TYPE); > cv.put(MediaStore.Audio.Media.ARTIST, > res.getString(R.string.audio_db_artist_name)); > cv.put(MediaStore.Audio.Media.ALBUM, > res.getString(R.string.audio_db_album_name)); > Log.d(TAG, "Inserting audio record: " + cv.toString()); > ContentResolver resolver = getContentResolver(); > Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; > Log.d(TAG, "ContentURI: " + base); > Uri result = resolver.insert(base, cv); > Log.e(TAG, result.toString()); > if (result == null) { > new AlertDialog.Builder(this) > .setTitle(R.string.app_name) > .setMessage(R.string.error_mediadb_new_record) > .setPositiveButton(R.string.button_ok, null) > .setCancelable(false) > .show(); > return null; > } > if (getPlaylistId(res) == -1) { > createPlaylist(res, resolver); > } > int audioId = Integer.valueOf(result.getLastPathSegment()); > addToPlaylist(resolver, audioId, getPlaylistId(res)); > > // Notify those applications such as Music listening to the > // scanner events that a recorded audio file just created. > sendBroadcast(new Intent > (Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, result)); > return result; > } > > ========================================================================== > > and I`ve put all of my files from sdcard. > > ========================================================================== > > private void makePlaylist() > { > String[] cols = new String[] { > MediaStore.Audio.Playlists._ID, > MediaStore.Audio.Playlists.NAME > }; > > String status = Environment.getExternalStorageState(); > Uri uri; > > if (status.equals(Environment.MEDIA_MOUNTED)) > list_path = new File("/sdcard"); > else > list_path = new File("/data/sec_media"); > > File f_list[] = list_path.listFiles(); > > f_len = f_list.length; > > for(int i=0;i < f_len ; i++){ > uri = addToMediaDB(f_list[i]); > } > } > > ========================================================================== > > According to logs, media files was in MediaStore.Audio.Media > > ========================================================================== > > 02-25 02:13:20.385: DEBUG/SoundRecorder(1057): Inserting audio record: > is_music=0 mime_type=audio/amr artist=Your recordings title=2009-02-25 > 02:13:20 _data=/sdcard/recording13246.amr date_modified=1235030668 > album=Audio recordings date_added=1235528000 > > 02-25 02:13:20.385: DEBUG/SoundRecorder(1057): ContentURI: > content://media/external/audio/media > > 02-25 02:13:20.415: ERROR/SoundRecorder(1057): > content://media/external/audio/media/322 > > ========================================================================== > > I thought "322" was_ID. > > However when I excute program, error has occured. > > I`d like show my audio file through ListView. > > ========================================================================== > > public class MyPlaylist extends ListActivity { > SoundRecorder mSr; > Uri playlist_uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; > > String[] projection = new String[] { > MediaStore.Audio.Media.TITLE, > MediaStore.Audio.Media.ARTIST > }; > > @Override > protected void onCreate(Bundle savedInstanceState) { > // TODO Auto-generated method stub > super.onCreate(savedInstanceState); > > setContentView(R.layout.playlist); > Log.e("Playlist","onCreate"); > > Cursor cursor = managedQuery(playlist_uri, projection, null, > null, > null); > > // Used to map notes entries from the database to views > SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, > R.layout.play_row, cursor, new String[] > {MediaStore.Audio.Media.TITLE }, new int[] {R.id.text1}); > setListAdapter(adapter); > } > > } > > ========================================================================== > > and here are error message. > > ========================================================================== > > 02-25 02:13:24.065: ERROR/AndroidRuntime(1057): Caused by: > java.lang.IllegalArgumentException:column'_id'doesnotexist > > ========================================================================== > > I couldn`t find any solutions. > > I think there are some problem when I`m using content provider. > > But for me, it is very difficult to understand. > > Could you please give me a solution? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---