我正在从麦克风录制一些音频,然后将其上传到服务器。
但上传时有一个问题。文件名不匹配。
我正在使用时间戳创建文件名,当我将该文件名传递给上传功能时,文件名的变化为2秒。例如,如果我的文件名为File_1234
,则传递为File_1236
。文件在存储时保存为File_1234
,但上传功能正在查找File_1236
创建文件的功能:
private File makeOutputFile () {
mPath1 = Environment.getExternalStorageDirectory();
mFileName1 = "/Call" + "_" + getTimeStamp() + ".3gp";
mFileStorageDirectory1 = new File(mPath1 + "/SalesLineCallRecordings");
if (!mFileStorageDirectory1.exists()) {
if (!mFileStorageDirectory1.mkdirs()) {
return null;
}
}
mFile1 = new File(mFileStorageDirectory1.getPath() + mFileName1);
mFilePath1 = mFile1.getAbsolutePath();
return mFile1;
}
获取时间戳:
public static String getTimeStamp() {
Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
simpleDateFormat.setTimeZone(TimeZone.getDefault());
return simpleDateFormat.format(calendar.getTime());
}
上传功能:
private void uploadActivity(boolean isConnected) {
if (isConnected) {
Log.e("", "File path" + mFilePath1);
//new UploadAsync().execute(mFilePath);
type1 = "yes";
Intent intent = new Intent(getBaseContext(), UploadService.class);
intent.putExtra("type", type1);
intent.putExtra("audioFile", mFilePath1);
startService(intent);
}
else {
audio.setAudioRecording(mFilePath1);
audioDbHelper.addAudio(audio);
}
}