aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes JMF Problems with cut.java sample Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JMF Problems with cut.java sample" Watch "JMF Problems with cut.java sample" New topic
Author

JMF Problems with cut.java sample

Angel J Gama
Ranch Hand

Joined: Jun 28, 2007
Posts: 36
Hi
I'm using JMF to extract the first 20 seconds from an mp3 file. I have copy-paste the example provided at http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Cut.html but I can't get it to work.
The error I'm getting back is:


Because I'm using eclipse as IDE, I made some "minor" changes on Cut.java to test it on eclipse:



Does any one have an idea what do I'm doing wrong? I'll appreciate your help.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61651
    
  67

"Angel JGM", please check your private messages.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Angel J Gama
Ranch Hand

Joined: Jun 28, 2007
Posts: 36
In case anyone needs, I found the solution:


import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;


FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
if(bis!=null) {
response.setContentType("audio/mpeg3");
response.setHeader("Content-Disposition", " inline; filename=cancion.mp3");
ServletOutputStream out = response.getOutputStream();
byte[] buffer = new byte[4 * 1024];
int maxTamano = 30*(bitrate*1024); // desired_seconds*(song's bitrate*1024)
int data = bis.read(buffer);
int totDataRead = data*8;
while(data != -1 && totDataRead<maxTamano) {
out.write(buffer, 0, data);
data = bis.read(buffer);
totDataRead+=data*8;
}
out.flush();
}
Virgilio Catubig
Greenhorn

Joined: Nov 28, 2012
Posts: 3
where response came from?? right now I encounter a problem that it seem I generate corrupted audio because it doesn't play.. this project I working is for android OS..

here's my code::

byte[] buffer = null;
InputStream fIn = null;

try {
fIn = new FileInputStream(this.currentDirectory.getAbsolutePath()
+ "/" + this.directoryEntries.get(pos));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

System.out.println(this.currentDirectory.getAbsolutePath() + "/"
+ this.directoryEntries.get(pos));

FileOutputStream saving = null;
BufferedInputStream bis = new BufferedInputStream(fIn);
if (bis != null) {
System.out.println("bis ay may laman");
try {
saving = new FileOutputStream(extStorageDirectory + "/"
+ soundTitle + ".mp3");
} catch (FileNotFoundException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (NullPointerException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

buffer = new byte[4 * 1024];
int maxTamano = 30 * (128 * 1024); // desired_seconds*(song's
// bitrate*1024)
int data = 0;
try {
data = bis.read(buffer);

int totDataRead = data * 8;
int p = 0;
while (data != -1 && totDataRead < maxTamano) {
p++;
System.out.println("write write"+p);
saving.write(buffer, 0, data);
data = bis.read(buffer);
totDataRead += data * 8;

}
fIn.close();
saving.flush();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (NullPointerException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}

is there anybody can correct my code..?
Virgilio Catubig
Greenhorn

Joined: Nov 28, 2012
Posts: 3
Sorry my mistake the code I posted is already working i detected the problem from dif. issues.. thank Angel J Gama for posting your code here it really help...
Virgilio Catubig
Greenhorn

Joined: Nov 28, 2012
Posts: 3
Hello again I have another problem what should I do to get the bitrate? and other problem is some mp3 has no bitrate..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JMF Problems with cut.java sample