Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

get audio files (wave) type from an arraylist

Posted on 2004-04-08
13
Medium Priority
?
418 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 1400 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

618 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