gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 23:35:02 26 4
gpt4 key购买 nike

我已经可以使用 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;
}
如何在我的应用程序中获得剪切的文件音乐???

最佳答案

检查是否保存在沙盒路径中,因为权限问题查询无法获取到沙盒路径中的文件,可以自行遍历软件的沙盒目录

关于ffmpeg - 我无法在我的应用程序中获取剪切的音乐文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69764698/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com