Solved

get audio files (wave) type from an arraylist

Posted on 2004-04-08
13
410 Views
Last Modified: 2010-03-31
How would a person get audio files (wave) type from an arraylist into this code


AudioInputStream asold = audioStream;
audioStream = AudioSystem.getAudioInputStream(getFormat(), asold);

private AudioInputStream getCurrentStream()
{
 return (AudioInputStream) m_audioInputStreamList.get(m_nCurrentStream);
}
0
Comment
Question by:Drop_of_Rain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
  • +1
13 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 10789502
If I understand you correctly

This Would help you

AudioInputStream asold = audioStream;
audioStream = AudioSystem.getAudioInputStream(getFormat(), asold);


private AudioInputStream getCurrentStream()
{
 return (AudioInputStream) m_audioInputStreamList.get(m_nCurrentStream);
}


  static class StreamFilter
        implements FilenameFilter
    {

        public boolean accept(File dir, String name)
        {
            name = name.toLowerCase();
            return name.endsWith(".wav");
        }

        StreamFilter()
        {
        }
    }

      public void LoadStreams(String folder)
      {
            File fl = new File(folder);
        String[]     fnames = fl.list(new DocFilter());
            for(int i=0;i<fnames.length;i++)
            {
                  AudioInputStream stream =       AudioSystem.getAudioInputStream(         new File(folder+"/"+fnames[i]));
                  m_audioInputStreamList.add(stream)
                  
            }

      }

ArrayList      m_audioInputStreamList=new ArrayList();


Regards
Sudhakar

0
 

Author Comment

by:Drop_of_Rain
ID: 10789542
public boolean accept(File dir, String name)

Is this getting the files from a File directory
0
 

Author Comment

by:Drop_of_Rain
ID: 10789547
If so, the files have to come from an arraylist because they are placed into the arraylist  by other code
0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 37

Expert Comment

by:zzynx
ID: 10789574
Don't understand what you want.

What does your array list contains? File objects? All of type *.wav?
And you want to get the AudioInputStreams of each File?
Is that your Q?
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10789578
Hi there friend;

Always check your e-mail on yahoo because thats the one which I use to send you any e-mail
I'm already working w/ your project, Just give me an ample time to finish it anyways
here is the answer to your above question

> If so, the files have to come from an arraylist because they are placed into the arraylist  by other code

Then just use this method :

     public void LoadStreams()
     {
        File files = new File("YourFolder/YourFile.wav");
        AudioInputStream stream = AudioSystem.getAudioInputStream(files);
        ArrayList  mylist = new ArrayList();
        mylist.add(stream);      
     }

Hope that helps . . .
Javatm
0
 

Author Comment

by:Drop_of_Rain
ID: 10789602
If so, the files have to come from an arraylist because they are placed into the arraylist  by other code

 File files = new File("YourFolder/YourFile.wav");
        AudioInputStream stream = AudioSystem.getAudioInputStream(files);
        ArrayList  mylist = new ArrayList();
        mylist.add(stream);      

They can't come from a folder or a directory. These files are placed into an arraylist from checkboxs being checked.

for(int i = 0; i < checkboxes.length; i++) {
     checkboxes[i].setActionCommand("kp" + (i + 1) + ".wav");
     choices.add(checkboxes[i]);//go through checkboxs and add them to choices

The Arraylist is called choices that contain the audio files, as can be seen from the above code. How would I get the files from (choices) into:

AudioInputStream asold = audioStream;
audioStream = AudioSystem.getAudioInputStream(getFormat(), asold);

private AudioInputStream getCurrentStream()
{
 return (AudioInputStream) m_audioInputStreamList.get(m_nCurrentStream);
}
0
 

Author Comment

by:Drop_of_Rain
ID: 10789620
zzynx

What does your array list contains? File objects? All of type *.wav?
And you want to get the AudioInputStreams of each File?
Is that your Q?

Yes, they are all .wav files.
 
And you want to get the AudioInputStreams of each File?

Yes, I need to create a single audiostream from all of the smaller .wav file streams.

audioStream = AudioSystem.getAudioInputStream(getFormat(), asold);

private AudioInputStream getCurrentStream()
0
 
LVL 37

Accepted Solution

by:
zzynx earned 350 total points
ID: 10789631
public void LoadStreams() {
        for (int i=0; i<choices.size(); i++) {
           File file = new File( ((JCheckBox)choices.get(i)).getActionCommand() );
           AudioInputStream stream = AudioSystem.getAudioInputStream(file);
           // do what you want with the stream
        }
}
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10789636
>> I need to create a single audiostream from all of the smaller .wav file streams.
Sorry, hadn't read your last post when posting the previous
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10789648
> They can't come from a folder or a directory. These files are placed into an arraylist from checkboxs being checked.

Well I'm just showing you how you should do it but if you want it by codes then zzynx answer is fair enough
I'm checking the codes that you sent me and I'm finding a way to use it or create a different sequence to
combine music files as what you want.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10789687
Maybe this?

public void produceOneFile() {

        File resultFile = new File("Total.wav");
        resultFile.createNewFile();
        FileOutputStream output = new FileOutputStream(resultFile);

        for (int i=0; i<choices.size(); i++) {
           File file = new File( ((JCheckBox)choices.get(i)).getActionCommand() );
           AudioInputStream stream = AudioSystem.getAudioInputStream(file);
           AudioSystem.write(stream, AudioFileFormat.Type.WAVE, output);
        }
        output.close();
}
0
 

Author Comment

by:Drop_of_Rain
ID: 10792717
zzynx:  I was just explaining why I was asking for the code to get audio streams from an arraylist. The comment you give:

public void LoadStreams() {
        for (int i=0; i<choices.size(); i++) {
           File file = new File( ((JCheckBox)choices.get(i)).getActionCommand() );
           AudioInputStream stream = AudioSystem.getAudioInputStream(file);
           // do what you want with the stream
        }
}

answered the question. Thanks so much for your help and contribution. I appreciate you being so responsive with answering questions.

Christopher
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10807853
>> Thanks so much for your help and contribution. I appreciate you being so responsive with answering questions.
Glad to hear that. :)
Thanks for accepting.
0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question