Jump to content

Help a beginner with adding sound

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
J_hollow

J_hollow

    Newbie

  • Members
  • Pip
  • 6 posts
I created this java file that suppose to output sound but when I run the file it doesnt seem to work.
All my sounds are wav formats around the size 200kb

Sound Class
import java.applet.*;

import javax.swing.*;

import java.io.*;

import java.net.*;


public class PlaySound extends JApplet

{


	public PlaySound()

    {

		filename="";

  	}


	public void loadSound(String s)

	{

		filename = s;


		try

        {

    		songPath = new URL(getCodeBase(),filename);

    		song = Applet.newAudioClip(songPath);

        }

        catch(MalformedURLException e)

        {

			e.printStackTrace();

		}


	}


  	public void playSound()

  	{

        song.loop();

 	}


  	public void stopSound()

  	{

    	song.stop();

  	}

 	public void playSoundOnce()

  	{

    	song.play();

  	}


  	private AudioClip song;

  	private URL songPath;

  	private String filename;

}


Main Class
public class tester

{

	public static void main(String[] args)

	{

		PlaySound s = new PlaySound();

		s.loadSound("sound.wav");

		s.playSound();

	}

}


Error:
Exeption in thread "main" java.lang.NullPointerException
at java.applet.Applet.getCodeVase<Appler.java:152>
at PlaySound.loadSound<PlaySound.java:20>
at tester.main<tester.java:6>

#2
J_hollow

J_hollow

    Newbie

  • Members
  • Pip
  • 6 posts
Nevermind Problem solved.