Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Problem with Audio Files

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    12
    Thanks
    0
    Thanked 6 Times in 2 Posts

    Default Problem with Audio Files

    Hi friends

    im new at this topic and i have tried all the things to make it work but without results ..

    can you please tell me whats not going in this simple code ??

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package rada;
     
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.*;
    import javax.swing.*;
    import sun.audio.*;
     
     
    public class Rada implements ActionListener{
    JFrame f = new JFrame("adga");
    JButton btt;
    Rada (){
        f.setBounds(100,100,200,200);
        f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
     
        btt = new JButton("Start");
        btt.addActionListener(this);
        f.add(btt);
        f.setVisible(true);
    }
     
    public void actionPerformed(ActionEvent ae) {
        if (ae.getSource()==btt){
            String st ="1.wav";
            try{
                InputStream in = new FileInputStream(st);
                AudioStream as = new AudioStream(in);
     
                AudioPlayer.player.start(as);
            }catch(IOException e){}
        }
    }
    public static void main(String[] args){
        Rada rd =new Rada();
    }
     
    }


    i have tried to copy the file audio 1.wav into the main folder of project and in the src folder too. but it doest works ...

    is there any good soul which can help me ??


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: Problem with Audio Files

    Quote Originally Posted by haiderali View Post
    i have tried all the things to make it work but without results ..
    What does it do? What should it do instead? Are there any error messages?

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    12
    Thanks
    0
    Thanked 6 Times in 2 Posts

    Default Re: Problem with Audio Files

    no ... there are no error messages ...
    it should play the audio in background when i push the button ! .... but unfortunatly it dsnt do nythng

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,156
    My Mood
    Hungover
    Thanks
    141
    Thanked 595 Times in 510 Posts

    Default Re: Problem with Audio Files

    You have an empty catch block. How would you know if it was throwing an Exception?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    May 2013
    Posts
    12
    Thanks
    0
    Thanked 6 Times in 2 Posts

    Default Re: Problem with Audio Files

    i have added the sout(ex); in catch field

    and when i push the button it gives me this error :

    java.io.IOException: could not create audio stream from input stream

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,156
    My Mood
    Hungover
    Thanks
    141
    Thanked 595 Times in 510 Posts

    Default Re: Problem with Audio Files

    Well, time to start debugging your code. Where is that file located? Where is Java looking for that file? Using relative paths can be tricky, so you have to be sure what's going on in every line.

    I suggest stepping through this with a debugger, or at least adding some print statements, to figure out what's going on.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Threads, Audio Application, Audio loading twice error
    By dpjmie in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 19th, 2013, 01:18 PM
  2. Problem reading in the files
    By Skynet928 in forum What's Wrong With My Code?
    Replies: 13
    Last Post: March 28th, 2013, 01:05 PM
  3. problem in sound files in created jar file
    By uttam24april in forum Member Introductions
    Replies: 48
    Last Post: December 16th, 2011, 06:19 AM
  4. HTK files from Java problem.
    By ivanloes in forum Java Theory & Questions
    Replies: 0
    Last Post: December 17th, 2010, 05:49 PM
  5. problem reading from two files into array objects
    By JavaRTnoob in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 30th, 2010, 09:21 AM