开发者

problem while inserting audio file in MediaStore.Audio.Media.EXTERNAL_CONTENT_URI in android

开发者 https://www.devze.com 2023-01-20 08:56 出处:网络
my code is like this ContentValues values = new ContentValues(); values.put(MediaStore.Audio.Media._ID, _ID);

my code is like this

ContentValues values = new ContentValues();

    values.put(MediaStore.Audio.Media._ID, _ID);
        values.put(MediaStore.Audio.Media.DATA, DATA);
        values.put(MediaStore.Audio.Media.DISPLAY_NAME, DISPLAY_NAME);
        values.put(MediaStore.Audio.Media.SIZE, SIZE);
        values.put(MediaStore.Audio.Media.MIME_TYPE, MIME_TYPE);
        values.put(MediaStore.Audio.Media.DATE_ADDED, DATE_ADDED);
        values.put(MediaStore.Audio.Media.DATE_MODIFIED, DATE_MODIFIED);
        values.put(MediaStore.Audio.Media.TITLE, TITLE);
        values.put(MediaStore.Audio.Media.TITLE_KEY, TITLE_KEY);
        values.put(MediaStore.Audio.Media.DURATION, DURATION);
        values.put(MediaStore.Audio.Media.ARTIST_ID, ARTIST_ID);
        values.put(MediaStore.Audio.Media.COMPOSER, COMPOSER);
        values.put(MediaStore.Audio.Media.ALBUM_ID, ALBUM_ID);
        values.put(MediaStore.Audio.Media.TRACK, TRACK);
        values.put(MediaStore.Audio.Media.YEAR, YEAR);
        values.put(MediaStore.Audio.Media.IS_RINGTONE, IS_RINGTONE);
        values.put(MediaStore.Audio.Media.IS_ALARM, IS_ALARM);
        values.put(MediaStore.Audio.Media.IS_NOTIFICATION, IS_NOTIFICATION);
        values.put(MediaStore.Audio.Media.IS_PODCAST, IS_PODCAST);
        values.put(MediaStore.Audio.Media.BOOKMARK, BOOKMARK);
        values.put(MediaStore.Audio.Media.ARTIST_KEY, ARTIST_KEY);
        values.put(MediaStore.Audio.Media.ARTIST, ARTIST);
        values.put(MediaStore.Audio.Media.ALBUM_KEY, ALBUM_KEY);
        values.put(MediaStore.Audio.Media.ALBUM, ALBUM);
        Uri uri = getContentResolver().insert(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values);
        try {
            OutputStream outStream = getContentResolver().openOutputStream(uri);
            outStream.write(buffer);
            outStream.close();

        } catch (Exception e) {
            Log.e("insetAudio", "exception inserting audio", e);
        }

it gives me exception that there is no column in audio_meta named artist_key

10-19 17:14:22.491: INFO/Database(214): sqlite returned: error code = 1, msg = table audio_meta has no column named artist_key 10-19 17:14:22.543: ERROR/Database(214): Error inserting artist_key=%D%<%8%<%R%,%B% is_alarm=0 is_ringtone=0 is_podcast=0 composer=null title=Vivuzela mime_type=audio/mpeg _id=5 date_added=1287488662 _display_name=vuvuzela.mp3 album_key=%,%<%D%P%%D%<%8%<%R%,%B%%R%4%0%:%F%H%V%<%,%R%<%H%F%P%%J%V%R%%B%R%2%-1882603603 year=2010 _size=498344 _data=/mnt/sdcard/Android/data/vuvuzela.mp3 bookmark=null date_modified=1287374780 track=0 artist_id=1 album_id=4 duration=31112 is_notification=0 title_key=%V%<%V%T%^%4%B%,% 10-19 17:14:22.543: ERROR/Database(214): android.database.sqlite.SQLiteException: table audio_meta has no column named artist_key: , while compiling: INSERT INTO audio_meta(artist_key, is_alarm, is_ringtone, is_podcast, composer, title, mime_type, _id, date_added, _display_name, album_key, year, _size, _data, bookmark, date_modified, track, artist_id, album_id, duration, is_notification, title_key) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); 10-19 17:14:22.543: ERROR/Database(214): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 10-19 17:14:22.543: ERROR/开发者_StackOverflowDatabase(214): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91) 10-19 17:14:22.543: ERROR/Database(214): at android.database.sqlite.SQLiteCompiledSql.(SQLiteCompiledSql.java:64) 10-19 17:14:22.543: ERROR/Database(214): at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:80) 10-19 17:14:22.543: ERROR/Database(214): at android.database.sqlite.SQLiteStatement.(SQLiteStatement.java:36) 10-19 17:14:22.543: ERROR/Database(214): at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1145) 10-19 17:14:22.543: ERROR/Database(214): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1536) 10-19 17:14:22.543: ERROR/Database(214): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1410) 10-19 17:14:22.543: ERROR/Database(214): at com.android.providers.media.MediaProvider.insertInternal(MediaProvider.java:1813) 10-19 17:14:22.543: ERROR/Database(214): at com.android.providers.media.MediaProvider.insert(MediaProvider.java:1638) 10-19 17:14:22.543: ERROR/Database(214): at android.content.ContentProvider$Transport.insert(ContentProvider.java:174) 10-19 17:14:22.543: ERROR/Database(214): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:146) 10-19 17:14:22.543: ERROR/Database(214): at android.os.Binder.execTransact(Binder.java:288) 10-19 17:14:22.543: ERROR/Database(214): at dalvik.system.NativeStart.run(Native Method)

can anybody help me whts wrong with my code although i can see coulmn artist_key while getting values from cursor from this uri and also value for that but when i want to insert value it throws exception

thanks in advance


You shouldn't try to put into ARTIST_KEY field any value, since it's calculated by Android's internal functions based on ARTIST field value. Smth like hash value or so.

0

精彩评论

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