tags:

views:

26

answers:

1

HI

I am trying to play an audio file in my Java application:

here is the code:

public static void music() 
    {       


  AudioPlayer MGP = AudioPlayer.player;
     AudioStream BGM;
     AudioData MD;

     ContinuousAudioDataStream loop = null;

     try
     {
      BGM = new AudioStream(new FileInputStream("\\BattleShip\\battle.wav"));
      MD = BGM.getData();
      loop = new ContinuousAudioDataStream(MD);

     }
     catch(FileNotFoundException e){
      System.out.print(e.toString());
     }
     catch(IOException error)
     {
      System.out.print(error.toString());
     }
     MGP.start(loop);

    }

I have no idea what this exception means or if it is even finding the wav file im trying to play

java.io.IOException: could not create AudioData object

thanks

+1  A: 

Thank got it working. Changed the code to:

public static void music() 
    {       


        AudioPlayer MGP = AudioPlayer.player;
        AudioStream BGM;
        AudioData MD;

        ContinuousAudioDataStream loop = null;

        try
        {
            InputStream test = new FileInputStream("./battle.wav");
            BGM = new AudioStream(test);
            AudioPlayer.player.start(BGM);
            //MD = BGM.getData();
            //loop = new ContinuousAudioDataStream(MD);

        }
        catch(FileNotFoundException e){
            System.out.print(e.toString());
        }
        catch(IOException error)
        {
            System.out.print(error.toString());
        }
        MGP.start(loop);

    }
You should probably remove the line MGP.start(loop); too.
Arnold Spence