Android examples for android.media:Audio
write Audio To Media
import java.io.File; import android.content.ContentValues; import android.content.Context; import android.net.Uri; import android.provider.MediaStore; import android.text.TextUtils; public class Main{ /**/*from ww w . j a va 2 s.c o m*/ * * @deprecated * <br/> * Use {@link nl.changer.android.opensource.AudioUtils#saveAudio(Context)} * Insert an audio into {@link MediaStore.Images.Media} content provider of the device. * * @return The media content Uri to the newly created audio, or null if failed for any reason. * ***/ public static Uri writeAudioToMedia(Context ctx, File audioFile) { ContentValues values = new ContentValues(); values.put(MediaStore.MediaColumns.DATA, audioFile.getAbsolutePath()); values.put(MediaStore.MediaColumns.TITLE, ""); values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mpeg"); values.put(MediaStore.MediaColumns.SIZE, audioFile.length()); values.put(MediaStore.Audio.Media.ARTIST, ""); values.put(MediaStore.Audio.Media.IS_RINGTONE, false); // Now set some extra features it depend on you values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false); values.put(MediaStore.Audio.Media.IS_ALARM, false); values.put(MediaStore.Audio.Media.IS_MUSIC, false); Uri uri = MediaStore.Audio.Media.getContentUriForPath(audioFile .getAbsolutePath()); Uri uri2 = ctx.getContentResolver().insert(uri, values); if (uri2 == null || TextUtils.isEmpty(uri2.toString())) { } return uri2; } }