Results 1 to 9 of 9
Like Tree2Likes
  • 1 Post By SurfMan
  • 1 Post By SurfMan

Thread: Java Sound: Exception on javax.sound.sampled.AudioSystem.getAudioInputStrea m()

  1. #1
    ScottVal is offline Member
    Join Date
    Jan 2009
    Posts
    44
    Rep Power
    0

    Default Java Sound: Exception on javax.sound.sampled.AudioSystem.getAudioInputStrea m()

    Hello-
    I'm learning to process sound in Java, and I thought I would start with the "javax.sound.sampled" package. I thought I would open a wav file and then play it through my computer's speaker.

    I'm calling javax.sound.sampled.AudioSystem. getAudioInputStream(InputStream), and getting an exception, and now I'm feeling kind of lost. The exception is:
    java.io.IOException: mark/reset not supported

    I guess it means I need some kind of better AudioInputStream class (one which supports mark/reset), or maybe it doesn't like the wav file which I picked? (I just picked some random wav file out of a /Windows/Media directory, like "alarm01.wav".)

    Here is the code:
    Java Code:
    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.sound.sampled.*;
    
    public class AudioTest extends JFrame {
        public AudioTest() {
            super("AudioTest");
        }
        
        public void init() {
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
            setSize(800, 400);
            
            FileDialog f = new FileDialog(this, "Pick a File");
            f.setVisible(true);
            String s = f.getDirectory();
            s += f.getFile();
            System.out.println("File Name:  " + s);
            
            FileInputStream i = null;
            try {
                i = new FileInputStream(s);
            } catch(Exception e) {
                System.out.println("Error opening file:  " + e);
                System.exit(1);
            }
            
            AudioInputStream a;
            try {
                a = AudioSystem.getAudioInputStream(i);
            } catch(Exception e) {
                System.out.println("Error getting audio stream:  " + e);
                System.exit(1);
            }
        }
        
        public static void main(String[] a) {
            AudioTest at = new AudioTest();
            at.init();
        }
    }
    -Scott

  2. #2
    ScottVal is offline Member
    Join Date
    Jan 2009
    Posts
    44
    Rep Power
    0

    Default Re: Java Sound: Exception on javax.sound.sampled.AudioSystem.getAudioInputStrea m()

    Maybe I need to use a BufferedInputStream??

  3. #3
    ScottVal is offline Member
    Join Date
    Jan 2009
    Posts
    44
    Rep Power
    0

    Default Re: Java Sound: Exception on javax.sound.sampled.AudioSystem.getAudioInputStrea m()

    Yes, that seems to be it. Now on to learning to use Clip()...

  4. #4
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,983
    Rep Power
    8

    Default Re: Java Sound: Exception on javax.sound.sampled.AudioSystem.getAudioInputStrea m()

    Don't you just love it when you can answer your own question?

    This is a phenomenon called "Rubber duck debugging". The idea here is that you put a rubber duck on your desk, and explain your problem to it. I have that when I explain a bug to my collegue and without him saying a single word, I manage to solve it by just explaining it to him. He just nods at me :) The rubber duck has the same function, but it prevents you from disturbing your collegues.

    Java Sound:  Exception on javax.sound.sampled.AudioSystem.getAudioInputStrea m()-rubber_duck_assisting_with_debugging.jpg
    By Tom Morris - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/inde...curid=16745966
    DarrylBurke likes this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,966
    Rep Power
    31

    Default Re: Java Sound: Exception on javax.sound.sampled.AudioSystem.getAudioInputStrea m()

    when I explain a bug to my collegue and without him saying a single word, I manage to solve it by just explaining it to him. He just nods at me :)
    We used to call that the "cardboard programmer".
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    ScottVal is offline Member
    Join Date
    Jan 2009
    Posts
    44
    Rep Power
    0

    Default Re: Java Sound: Exception on javax.sound.sampled.AudioSystem.getAudioInputStrea m()

    Ha ha, I'll have to get a rubber duck. Or a cardboard cut-out of a programmer.

  7. #7
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    398
    Rep Power
    5

    Default Re: Java Sound: Exception on javax.sound.sampled.AudioSystem.getAudioInputStrea m()

    What is the second rubber duck good for? Your colleague, so he has sb to talk to?

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Java Sound: Exception on javax.sound.sampled.AudioSystem.getAudioInputStrea m()

    Quote Originally Posted by ScottVal View Post
    Ha ha, I'll have to get a rubber duck. Or a cardboard cut-out of a programmer.
    You can use my avatar :)
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,983
    Rep Power
    8

    Default Re: Java Sound: Exception on javax.sound.sampled.AudioSystem.getAudioInputStrea m()

    Quote Originally Posted by DarrylBurke View Post
    You can use my avatar :)
    Maybe he needs a bigger one:
    Java Sound:  Exception on javax.sound.sampled.AudioSystem.getAudioInputStrea m()-binario.jpg
    DarrylBurke likes this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Replies: 0
    Last Post: 04-27-2016, 01:27 PM
  2. No proper soundplaying with Javax.sound.sampled
    By sandydo in forum New To Java
    Replies: 1
    Last Post: 04-05-2014, 02:35 PM
  3. Replies: 1
    Last Post: 06-23-2013, 01:52 PM
  4. Details using javax.sound.sampled
    By toadaly in forum Advanced Java
    Replies: 0
    Last Post: 04-20-2010, 05:37 AM
  5. javax.sound.sampled
    By carderne in forum New To Java
    Replies: 5
    Last Post: 02-28-2009, 10:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •