Does anybody know how to cut a sound clip from running sound file? I am working on one blackberry application, Is anybody have any sample code or link please give me that.
Thanks
Regards 开发者_StackOverflow中文版V Singh
It is possible to cut a part of sound file. You have to study sound file formats and deal with sound file binary structure.
No, I don't have sample code, but you can write it by yourself, after studying sound file formats.
//Sample code to cut a sound file(AMR)
long startTime = player.getMediaTime(); long endTime = player.getMediaTime();
private void cutByTimeDuration(long startTime, long endTime) {
// TODO Auto-generated method stub
byte[] byte1 = readDSoundFile("hello.amr"); //custom method original file
int noFramesStart = (int) (startTime / 20000);
long noBytesStart = (noFramesStart * 32) + 6;
int noFramesEnd = (int) (endTime / 20000);
long noBytesEnd = (noFramesEnd * 32) + 6;
byte[] byte2 = new byte[(int) (noBytesEnd - noBytesStart + 6)];
System.arraycopy(byte1, 0, byte2, 0, 6);
System.arraycopy(byte1, (int) noBytesStart, byte2, 6,
(int) (noBytesEnd - noBytesStart));
try {
FileConnection file = (FileConnection) Connector.open(filePath
+ "/" + "xyz.amr", Connector.READ_WRITE);
if (file.exists())
file.delete();
// if (!file.exists() )
{
file.create();
OutputStream out = file.openOutputStream();
int length = byte2.length;// -1;
out.write(byte2, 0, length);
Thread.yield();
out.flush();
out.close();
file.close();
}
} catch (Exception e) {
}
}
精彩评论