我无法在我的应用程序中剪切音乐文件



我已经可以通过使用FFmpeg剪切音乐文件并保存在外部存储。但是我不能得到音乐文件切割,在我的应用程序播放音乐文件。

我已经使用这个代码来剪切音乐文件

private void trimMusic(long position_start, long position_end, String SONG_NAME) {
File folder = new File(Environment.getExternalStorageDirectory() + "/MusicEditor/");
folder.setReadable(true);
if (!folder.exists()) {
folder.mkdir();
}
String filePrefix = SONG_NAME;
String fileExt = ".mp3";
System.out.println("audio"+fileExt);
dest = new File(folder, filePrefix + fileExt);
original_path = path;
duration = (endMs - startMs) / 1000;
filePath = dest.getAbsolutePath();
Log.d("chandoixuanduc",filePath);
command = new String[]{"-ss", "" + startMs / 1000, "-y", "-i", original_path, "-t", "" + (endMs - startMs) / 1000, "-vcodec", "mpeg4", "-b:v", "2097152", "-b:a", "48000", "-ac", "2", "-ar", "22050", filePath};
execffmpegBinary(command);
}
private void execffmpegBinary(final String[] command) {
Config.enableLogCallback(new LogCallback() {
@Override
public void apply(LogMessage message) {
Log.e(Config.TAG, message.getText());
}
});
Config.enableLogCallback(new LogCallback() {
@Override
public void apply(LogMessage message) {
Log.e(Config.TAG, message.getText());
}
});
Config.enableStatisticsCallback(new StatisticsCallback() {
@Override
public void apply(Statistics newStatistics) {
}
});
Log.d(TAG, "Started command : ffmpeg " + Arrays.toString(command));

long executionId = FFmpeg.executeAsync(command, new ExecuteCallback() {
@Override
public void apply(long executionId, int returnCode) {
if (returnCode == RETURN_CODE_SUCCESS) {
//  progressDialog.dismiss();
dialog.dismiss();
Toast.makeText(getActivity(), R.string.status_cut_music_sus, Toast.LENGTH_LONG).show();
Log.d("chandoixuanduc","RETURN_CODE_SUCCESS");
}
else if (returnCode == RETURN_CODE_CANCEL) {
Log.d("chandoixuanduc","RETURN_CODE_CANCEL");
}
else {
Toast.makeText(getActivity(), R.string.status_cut_music_failed, Toast.LENGTH_LONG).show();
Log.d("chandoixuanduc","RETURN_CODE_FAILED");
}
}
});
}

虽然我检查了,但我的手机里有一个剪切的音乐文件,但是当我得到所有文件mp3进行测试时,我无法在我的应用程序中获得剪切的音乐文件。

public List<AudioModel> getAllAudioFromDevice(final Context context) {
final List<AudioModel> tempAudioList = new ArrayList<>();
try {
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String[] projection = {MediaStore.Audio.AudioColumns.DATA, MediaStore.Audio.AudioColumns.ALBUM, MediaStore.Audio.ArtistColumns.ARTIST,};
cursor = context.getContentResolver().query(uri,
projection,
null,
null,
null);
if (cursor != null) {
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
AudioModel audioModel = new AudioModel();
String path = cursor.getString(0);
String album = cursor.getString(1);
String artist = cursor.getString(2);
String name = path.substring(path.lastIndexOf("/") + 1);
Uri urisong=Uri.parse(cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA)));
MediaPlayer mp = MediaPlayer.create(getActivity(), urisong);
long duration=mp.getDuration();
audioModel.setaName(name);
audioModel.setaAlbum(album);
audioModel.setaArtist(artist);
audioModel.setaPath(path);
audioModel.setDuration(duration);
audioModel.setUri(urisong);
Log.d("kskskskkd",audioModel.duration+"  "+audioModel.uri);
tempAudioList.add(audioModel);
cursor.moveToNext();
}
cursor.close();
}
}catch (Exception e){
}
return tempAudioList;
}

如何在我的应用程序中剪切文件音乐??

检查是否保存在沙箱路径下,由于权限问题查询无法获取沙箱路径下的文件,可以自己遍历软件的沙箱目录

相关内容

  • 没有找到相关文章

最新更新