Article View: borland.public.jbuilder.java.api
Article #1940sound files using java.sound.sampled.*
From: Blue Presley
Date: Sun, 15 Jul 2001 06:49
Date: Sun, 15 Jul 2001 06:49
107 lines
3627 bytes
3627 bytes
Hello. I 3 clips in a directory and I want to play them in succession ie
one after the other. However I don't know how to make the program know that
one file is finished and that the next one (in the array) should be started.
The code works, but only the first file plays. Here is my code. I actually
start playing the file at the very bottom and I'm sure this is where my
problem is, but I've included the entire file for reference.
import java.io.*;
import java.net.*;
import java.applet.*;
import javax.sound.sampled.*;
public class mixer
{
public static void main (String[] args)
{
File currentDir = new File(System.getProperty("user.dir"));
String[] filename = currentDir.list();
File soundfile0 = new File(currentDir, filename[0]);
File soundfile1 = new File(currentDir, filename[1]);
File soundfile2 = new File(currentDir, filename[2]);
File soundfile3 = new File(currentDir, filename[8]);
AudioInputStream source0 = null;
AudioInputStream source1 = null;
AudioInputStream source2 = null;
AudioInputStream source3 = null;
try
{
source0 = AudioSystem.getAudioInputStream(soundfile0);
source1 = AudioSystem.getAudioInputStream(soundfile1);
source2 = AudioSystem.getAudioInputStream(soundfile2);
source3 = AudioSystem.getAudioInputStream(soundfile3);
}
catch(UnsupportedAudioFileException e)
{
System.err.println(e);
}
catch(IOException ex){
System.err.println(ex);
}
Mixer.Info[] mixers = AudioSystem.getMixerInfo();
for (int x = 0;x < mixers.length; x++)
{
System.out.println(mixers[x].getName());
}
//AudioFormat format = new AudioFormat(44100.0f, 16, 2, true, true);
DataLine.Info clipInfo0 = new DataLine.Info(Clip.class,
source0.getFormat());
DataLine.Info clipInfo1 = new DataLine.Info(Clip.class,
source1.getFormat());
DataLine.Info clipInfo2 = new DataLine.Info(Clip.class,
source2.getFormat());
DataLine.Info clipInfo3 = new DataLine.Info(Clip.class,
source3.getFormat());
Clip clip0 = null;
Clip clip1 = null;
Clip clip2 = null;
Clip clip3 = null;
try
{
clip0 = (Clip)AudioSystem.getLine(clipInfo0);
clip1 = (Clip)AudioSystem.getLine(clipInfo1);
clip2 = (Clip)AudioSystem.getLine(clipInfo2);
clip3 = (Clip)AudioSystem.getLine(clipInfo3);
}
catch(LineUnavailableException e)
{
System.err.println(e);
}
try
{
clip0.open(source0);
clip1.open(source1);
}
catch(LineUnavailableException e){
System.err.println(e);
}
catch(IOException e){
System.err.println(e);
}
System.out.println(clip0.getFramePosition());
System.out.println(clip0.getFrameLength());
while(clip0.getFramePosition() < 11417)
{
clip0.start();
}
clip0.stop();
clip0.close();
clip1.start();
}
}
Technical Details
Message-ID:
<3b513abb$1_1@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!newsfeed.icl.net!feed2.onemain.com!feed1.onemain.com!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnewsShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,1edde0109258fbdf,start X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2001-07-14 23:41:41 PST From: "Blue Presley" <blue928@carolina.rr.com> Newsgroups: borland.public.jbuilder.java.api Subject: sound files using java.sound.sampled.* Date: Sun, 15 Jul 2001 02:49:35 -0400 Lines: 109 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2462.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2462.0000 NNTP-Posting-Host: 152.2.239.192 Message-ID: <3b513abb$1_1@dnews> X-Trace: dnews 995179195 152.2.239.192 (14 Jul 2001 23:39:55 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!newsfeed.icl.net!feed2.onemain.com!feed1.onemain.com!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews