[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 420
  • Last Modified:

get audio files (wave) type from an arraylist

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
Drop_of_Rain
Asked:
Drop_of_Rain
  • 5
  • 5
  • 2
  • +1
1 Solution
 
sudhakar_koundinyaCommented:
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
 
Drop_of_RainAuthor Commented:
public boolean accept(File dir, String name)

Is this getting the files from a File directory
0
 
Drop_of_RainAuthor Commented:
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.

 
zzynxSoftware engineerCommented:
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
 
JavatmCommented:
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
 
Drop_of_RainAuthor Commented:
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
 
Drop_of_RainAuthor Commented:
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
 
zzynxSoftware engineerCommented:
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
 
zzynxSoftware engineerCommented:
>> 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
 
JavatmCommented:
> 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
 
zzynxSoftware engineerCommented:
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
 
Drop_of_RainAuthor Commented:
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
 
zzynxSoftware engineerCommented:
>> 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now