以编程方式重命名后,媒体文件损坏

问题描述 投票:0回答:1

我通过OmRecorder录制后以编程方式重命名“temp-record.mp3”文件,录制后和重命名文件之前,MP3文件似乎播放正常并且有效。但在将“temp-record.mp3”文件重命名为动态“userId-record-systime.mp3”之后,它会被破坏并且不会播放。

我正在使用以下函数重命名:

public static boolean renameFile(String fromFilePathWithExt,String toFilePathWithExt){
        LogUtils.d("from: "+fromFilePathWithExt);
        LogUtils.d("to: "+toFilePathWithExt);
        File dir = Environment.getExternalStorageDirectory();
        if(dir.exists()){
            File from = new File(fromFilePathWithExt);
            File to = new File(toFilePathWithExt);
            if(from.exists()) {
                return from.renameTo(to);
            }
        }
        return false;
    }

我也通知了这个issues in Omrecorder回购,但我仍然感到困惑,我做错了什么?

android mp3 file-rename android-file android-mediarecorder
1个回答
0
投票

尝试做:

new file(“loc / xyz1.mp3”)。renameTo(new File(“loc / xyz.mp3”));

这应该会自动覆盖原始文件。这个答案来自这里:enter link description here

© www.soinside.com 2019 - 2024. All rights reserved.