Add a mp3 to content provider (MediaStore.Audio.Media)

All your problems with Audio, Video and Images.

Add a mp3 to content provider (MediaStore.Audio.Media)

Postby jjoe64 » Tue Jan 05, 2010 12:31 am

Hello.

I get an error if I use this simple code:

import android.provider.MediaStore.Audio.Media;
// Save the name and description of an image in a ContentValues map.
ContentValues values = new ContentValues(3);
values.put(Media.DISPLAY_NAME, "road_trip_1");
values.put(Media.TITLE, "Day 1, trip to Los Angeles");
values.put(Media.MIME_TYPE, "audio/mp3");

// Add a new record without the bitmap, but with the values just set.
// insert() returns the URI of the new record.
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);

The error I get is on the last code line:
Writing exception to parcel
java.lang.NullPointerException
at com.android.providers.media.MediaProvider.insertInternal(MediaProvider.java:1286)
at com.android.providers.media.MediaProvider.insert(MediaProvider.java:1193)
(...)


But, when I insert a new image entry instead of an audio entry I get no error!
(import android.provider.MediaStore.Images.Media; instead of android.provider.MediaStore.Audio.Media; would work, but I need to insert a audio file)
jjoe64
Freshman
Freshman
 
Posts: 4
Joined: Tue Dec 29, 2009 6:04 pm

Top

Postby Dan S » Mon Jan 18, 2010 8:32 am

I am also having this problem. Which API level are you using?
Dan S
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Jan 18, 2010 8:20 am

Postby jjoe64 » Mon Jan 18, 2010 10:20 pm

I use API Level 4
But I guess in level 3 is the same problem...
jjoe64
Freshman
Freshman
 
Posts: 4
Joined: Tue Dec 29, 2009 6:04 pm

Postby qlimax » Tue Jan 19, 2010 12:12 am

just add some fake data
values.put(Media.DATA, "/data/data");

bye :wink:
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 16 guests