GeeCON Prague 2014*
The moose likes Java in General and the fly likes Unplayable file using java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Unplayable file using java" Watch "Unplayable file using java" New topic
Author

Unplayable file using java

Armando Festerelli Cambi
Greenhorn

Joined: Mar 30, 2010
Posts: 2
Hi,
can anyone help me ?
I wanto to play an audio file and whenever I press the stop button , the already played part of the file should be saved.
Unfortunately , what I get is an audio file (.wav) which actually is unplayable.

Thanks





//**************************
void play_cut() {

try {


// First, we get the format of the input file
final AudioFileFormat.Type fileType = AudioSystem.getAudioFileFormat(inputAudio).getType();
// Then, we get a clip for playing the audio.
c = AudioSystem.getClip();
// We get a stream for playing the input file.
AudioInputStream ais = AudioSystem.getAudioInputStream(inputAudio);
// We use the clip to open (but not start) the input stream
c.open(ais);
// We get the format of the audio codec (not the file format we got above)
final AudioFormat audioFormat = ais.getFormat();

c.start();
AudioInputStream startStream = new AudioInputStream(new FileInputStream(inputAudio), audioFormat, c.getLongFramePosition());
AudioSystem.write(startStream, fileType, outputAudio);


} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
}// end play_cut
//**************************
Jonas Isberg
Ranch Hand

Joined: Mar 18, 2003
Posts: 118
Hi and welcome Tom!
tom qwehnch wrote:can anyone help me ?

I am pretty sure that someone can. You can however help them help
you by considering to UseCodeTags and PostRealCode.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11465
    
  94

Please check your private messages regarding an important administrative matter.

Addressing Jonas' concerns, making this real code and using code tags:
(minor changes made for readability)

Hint: Take a look at the debug message I added at line 28 - does that look correct to you? Note that this matches up neatly with the debug message at line 32 - the expected amount to write + audio format header = output size.

Also - line 23 does not block. By the time you get to line 25 you do not know what state your playableClip is in - has it just started, has it completed, has the end user chosen how large they would like the resultant clip?

For that matter: is there even a need for line 23? I assume that this is where you are going to have your hook to allow the user to choose how much of the input they want to output, but for now it has no value.


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Armando Festerelli Cambi
Greenhorn

Joined: Mar 30, 2010
Posts: 2
Thank you.
So how should I address the problem . A knotty problem for me .
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

"tom moose", please check your private messages for an important administrative matter. Again.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
GeeCON Prague 2014
 
subject: Unplayable file using java