Solved

get audio files (wave) type from an arraylist

Posted on 2004-04-08
13
363 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
  • 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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
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 …

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now