简体   繁体   中英

how to cut or trim audio song in android programmatically?

I want to cut or trim audio song in android programmatically. i have found FFMPEG solution but i am not getting what is the step behind to cut audio song and if any other way please help me.

most people give me this type answer

ffmpeg -t 30 -i inputfile.mp3 -acodec copy outputfile.mp3

what is this and how to use in android code to cut audio?

Please help me.

Thank You

Basically follow the steps described here: http://writingminds.github.io/ffmpeg-android-java/

1.) You have to include the ffmpeg Library into your project! put this in your build.gradle File:

dependencies {compile 'com.writingminds:FFmpegAndroid:0.3.2'}

2.) before using the Lib, copy the binary file from assets to the device:

FFmpeg ffmpeg = FFmpeg.getInstance(context);
ffmpeg.loadBinary(new LoadBinaryResponseHandler() {...}

3.) when this is finished you can start executing commands and listen for the results like this:

ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {...}

where cmd is the array of arguments:

String[] command1 = new String[8];
command1[0]="-t";
command1[0]="30";
...

BUT: actually I found that the ffmpeg version for android does not work as expected for cutting or trimming audio files! (I got errors for commands that do work on linux commandline...) Hope you will figure it out.

There's a simple hack:

  1. figure out bytes per second or millisecond -- file.length()/duration
  2. get the start and end position where you want to cut audio.
  3. read file as bytes and save the portion between startPos and EndPos in separate file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM