Android视频编辑SDKImgly中应用远程URL下载的音频到视频时崩溃的问题
创始人
2024-10-10 12:32:21
0

在应用音频文件之前,先使用AsyncTask在后台线程中下载音频并保存到本地文件系统。然后,将该本地路径作为参数传递给Imgly Video Editor SDK中的音频应用方法。

代码示例:

private class DownloadAudioTask extends AsyncTask {

@Override protected String doInBackground(String... params) {

String url = params[0];
String fileName = params[1];
String path = Environment.getExternalStorageDirectory().toString() + "/" + fileName;

try {
    URLConnection connection = new URL(url).openConnection();
    InputStream inputStream = new BufferedInputStream(connection.getInputStream());
    OutputStream outputStream = new FileOutputStream(path);

    byte data[] = new byte[1024];
    int count;
    while ((count = inputStream.read(data)) != -1) {
        outputStream.write(data, 0, count);
    }

    outputStream.flush();
    outputStream.close();
    inputStream.close();

} catch (Exception e) {
    e.printStackTrace();
}

return path;

}

@Override protected void onPostExecute(String path) { applyAudioToVideo(path); }

}

private void applyAudioToVideo(String audioPath) { Video newVideo = new Video(videoPath); Filter videoResizer = new VideoSizeFilter(SizeConstraint.LIMIT_1080); newVideo.applyFilter(videoResizer);

Filter audioFilter = new AudioFilter(audioPath);
newVideo.addFilter(audioFilter);

newVideo.save(resultPath, new CompletionCallback() {
    @Override
    public void onError(Throwable e) {
        e.printStackTrace();
    }

    @Override
    public void onCompletion(Uri uri) {
        // completed
    }
});

}

其中,videoPath为要编辑的视频路径,resultPath为导出的视频路径。

相关内容

热门资讯

辅助透视!wepokerplu... 辅助透视!wepokerplus脚本,微信小程序微乐辅助器教程,课程教程(有挂总结)-哔哩哔哩1、下...
必备透视!pokemmo脚本,... 必备透视!pokemmo脚本,微信微乐自建房辅助工具,阶段教程(有挂存在)-哔哩哔哩1、进入游戏-大...
揭幕透视!wepoker私人局... 揭幕透视!wepoker私人局辅助器怎么用,微乐家乡小程序脚本,经验教程(证实有挂)-哔哩哔哩1、实...
解谜透视!wepoker有没有... 解谜透视!wepoker有没有插件,淘宝的微乐辅助是真的吗,方式教程(有挂方略)-哔哩哔哩在进入we...
关于透视!WePoKer辅助器... 关于透视!WePoKer辅助器,微乐河南小程序微乐辅助脚本,积累教程(了解有挂)-哔哩哔哩1、很好的...
详情透视!德普之星透视辅助软件... 详情透视!德普之星透视辅助软件下载,微乐陕西小程序脚本,要领教程(有挂头条)-哔哩哔哩1、德普之星透...
揭幕透视!wpk模拟器多开,微... 揭幕透视!wpk模拟器多开,微乐小程序卡五星脚本,手册教程(有挂工具)-哔哩哔哩1、点击下载安装,w...
专业透视!we poker辅助... 专业透视!we poker辅助器v3.3,微乐小程序游戏破解器苹果系统,练习教程(今日头条)-哔哩哔...
曝光透视!hhpoker真的假... 曝光透视!hhpoker真的假的,微信微乐游戏破解器,攻略教程(有挂解密)-哔哩哔哩1、hhpoke...
解密透视!hhpoker辅助软... 解密透视!hhpoker辅助软件下载,小程序微乐辅助器2.0,手段教程(揭秘有挂)-哔哩哔哩hhpo...