Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid : Unable to set new details of .mp3 file after cutting
    primarykey
    data
    text
    <p>I able to cut .mp3 file to desire seconds(only differ by 1 or 2 seconds) . but when i playing this file after cutting i still getting its old duration by "mediaplayer.getduration();" </p> <p>Eg. let my song duration is 4 min 6 sec and it cut it from 0 sec to 1 min . then when i play this i get its time 4 min 6 sec by mediaplayer.getduration() and song stop playing on 58 sec or 59 sec or 1 min and i am setting other details too like i set artist name "Madonna" but getting "unknown".</p> <p>So please help me how can set its correct time at the time of cutting and set other details too.</p> <p>This is my code: </p> <pre><code>path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC); String str = "xyz3.mp3"; File f = new File(path, str); // new file File file = new File("/sdcard/media/audio/music/mysong.mp3") //i am cutting this song CheapSoundFile csf = CheapSoundFile.create(file.getAbsolutePath(), listener ); int mSampleRate = csf.getSampleRate(); int mSamplesPerFrame = csf.getSamplesPerFrame(); int duration = (int)(seekBar.getSelectedMaxValue() - seekBar.getSelectedMinValue()+0.5); int startframe = (int)(1.0 * (double)(seekBar.getSelectedMinValue()/1000) * mSampleRate / mSamplesPerFrame + 0.5); int endframe = (int)(1.0 * (double)(seekBar.getSelectedMaxValue()/1000) * mSampleRate / mSamplesPerFrame + 0.5); csf.WriteFile(f, startframe, endframe - startframe); ContentValues values = new ContentValues(); values.put(MediaStore.MediaColumns.DATA, f.getAbsolutePath()); values.put(MediaStore.MediaColumns.TITLE, "My Song title"); values.put(MediaStore.MediaColumns.SIZE, f.length()); values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3"); values.put(MediaStore.Audio.Media.ARTIST, "Madonna"); values.put(MediaStore.Audio.Media.DURATION, duration); values.put(MediaStore.Audio.Media.IS_RINGTONE, false); values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false); values.put(MediaStore.Audio.Media.IS_ALARM, false); values.put(MediaStore.Audio.Media.IS_MUSIC, true); //Insert it into the database Uri uri = MediaStore.Audio.Media.getContentUriForPath(f.getAbsolutePath()); getContentResolver().insert(uri, values); sendBroadcast(new Intent("android.intent.action.MEDIA_MOUNTED",Uri.parse("file://" + Environment.getExternalStorageDirectory()))); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload