Adding MP3 to ContentProvider
<p>I'm trying to use an Mp3 on the SDCard as a ringtone.</p>

<p>I'm basing my code off various snippets/tutorials online, but none seem to be working.</p>

<p>I'm running FroYo. This is my code:</p>

<pre><code>    Uri uri = MediaStore.Audio.Media.getContentUriForPath(file.getAbsolutePath());
    ContentValues values = new ContentValues();
    values.put(MediaStore.MediaColumns.TITLE, "Title");
    values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
    values.put(MediaStore.MediaColumns.DATA, file.getAbsolutePath());
    values.put(MediaStore.Audio.Media.DATA, file.getAbsolutePath());
    values.put(MediaStore.Audio.Media.ARTIST, "Artist");
    values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
    values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
    values.put(MediaStore.Audio.Media.IS_ALARM, true);
    values.put(MediaStore.Audio.Media.IS_MUSIC, false);
    Uri newUri = getContentResolver().insert(uri, values);
</code></pre>

<p>This is the error I get</p>

<pre><code>08-20 18:48:39.878: ERROR/Database(31570): Error inserting album_id=-1 title=Title is_notification=true title_key=%R%&lt;%R%B%4% mime_type=audio/mp3 date_added=1282326519 _display_name=sb_ringtone_2.mp3 is_alarm=true is_ringtone=true artist_id=31 is_music=false _data=/mnt/sdcard/sb_ringtone_2.mp3
08-20 18:48:39.878: ERROR/Database(31570): android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed
08-20 18:48:39.878: ERROR/Database(31570):     at android.database.sqlite.SQLiteStatement.native_execute(Native Method)
08-20 18:48:39.878: ERROR/Database(31570):     at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:55)
08-20 18:48:39.878: ERROR/Database(31570):     at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1549)
08-20 18:48:39.878: ERROR/Database(31570):     at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1410)
08-20 18:48:39.878: ERROR/Database(31570):     at com.android.providers.media.MediaProvider.insertInternal(MediaProvider.java:1813)
08-20 18:48:39.878: ERROR/Database(31570):     at com.android.providers.media.MediaProvider.insert(MediaProvider.java:1638)
08-20 18:48:39.878: ERROR/Database(31570):     at android.content.ContentProvider$Transport.insert(ContentProvider.java:174)
08-20 18:48:39.878: ERROR/Database(31570):     at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:146)
08-20 18:48:39.878: ERROR/Database(31570):     at android.os.Binder.execTransact(Binder.java:288)
08-20 18:48:39.878: ERROR/Database(31570):     at dalvik.system.NativeStart.run(Native Method)
</code></pre>

<p>When I use newUri with the RingtoneManager, no exception is raised, but I get this error when the ringtone is 'played' (ie, somebody rings)</p>

<pre><code>08-20 18:49:28.318: ERROR/MediaPlayerService(26167): Couldn't open fd for content://settings/system/notification_sound
08-20 18:49:28.318: ERROR/MediaPlayer(26174): Unable to to create media player
08-20 18:49:28.318: WARN/NotificationService(26174): error loading sound for content://settings/system/notification_sound
08-20 18:49:28.318: WARN/NotificationService(26174): java.io.IOException: setDataSource failed.: status=0x80000000
08-20 18:49:28.318: WARN/NotificationService(26174):     at android.media.MediaPlayer.setDataSource(Native Method)
08-20 18:49:28.318: WARN/NotificationService(26174):     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:716)
08-20 18:49:28.318: WARN/NotificationService(26174):     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:671)
08-20 18:49:28.318: WARN/NotificationService(26174):     at com.android.server.NotificationPlayer$CreationAndCompletionThread.run(NotificationPlayer.java:88)
</code></pre>

<p>Any help would be greatly appreciated :)</p>
