• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JMF Problems with cut.java sample

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Angel JGM", please check your private messages.
 
Angel J Gama
Ranch Hand
Posts: 36
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello again I have another problem what should I do to get the bitrate? and other problem is some mp3 has no bitrate..
reply
    Bookmark Topic Watch Topic
  • New Topic