Solved

get audio files (wave) type from an arraylist

Posted on 2004-04-08
13
386 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Image decoding from Camera 3 85
servlet filter example 37 58
maven module vs maven project 3 21
Convert from a json string array to a Java object 3 28
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

816 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

9 Experts available now in Live!

Get 1:1 Help Now