?
Solved

Help! I've looped a sound file playing on the java browser and i cant stop it

Posted on 2005-04-16
11
Medium Priority
?
188 Views
Last Modified: 2010-03-31
I refreshed the browser and no i have the sound looping twice.

0
Comment
Question by:pigmentarts
  • 6
  • 5
11 Comments
 
LVL 92

Expert Comment

by:objects
ID: 13799574
you need to add code in your stop() method to sop the looping.
stop() gets called when the applet is stopped.
0
 
LVL 92

Expert Comment

by:objects
ID: 13799579
Whats happening is when you refresh your applet is stopped and then (re) started.
So stop() gets called, and then start() gets called (again).
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 13799583
I tried adding

public void stop() {
        if (looping) {
        loopClip.stop();    //Stop the sound loop.
    }
}

it says i'm missing a : symbol
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Author Comment

by:pigmentarts
ID: 13799591
ah iyes i see now, I thought it only kept looping in the browser, but clicking stop on the application does the same thing.

It doesnt just stop and start again, it starts playing twice!
0
 
LVL 92

Expert Comment

by:objects
ID: 13799598
you missed a closing }

public void stop() {
        if (looping) {
           loopClip.stop();    //Stop the sound loop.
        }
}
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 13799612
i still get an error..are you sure thats the problem? adding the '}' i get 3 errors saying class or interface expected

  //Start the applet
    public void start() {

        AudioClip clip = null;
        try {
            clip =
                    java.applet.Applet.newAudioClip(new java.net.URL(
                    getDocumentBase(), "1000Hz.au"));
        } catch (MalformedURLException ex) {
        }

      clip.play( );

    }

}  // <--------ADDED BRACKET

    //Stop the applet
    public void stop() {
         if (looping) {
            loopClip.stop();    //Stop the sound loop.
         }
 }


    //Destroy the applet
    public void destroy() {
    }
0
 
LVL 92

Expert Comment

by:objects
ID: 13799619
}  // <--------ADDED BRACKET

remove that bracket :)
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 13799631
but then i get the other errors :P

cannot find symbol; symbol : variable looping, location: class jas.PlaySound
cannot find symbol; symbol : variable loopClip, location: class jas.PlaySound
0
 
LVL 92

Expert Comment

by:objects
ID: 13799647
sorry didn't look closely enuf at your code, I was assuming that those variables already existed :)
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 13799680
Heh, i wouldnt assume when i'm around :)  I havent touched Java in about 2 years and just finding my fingers again.

I've added variables like this, but only for 2 errors to be replaced by 1 (its progress i suppose :)



  //Stop the applet
    public void stop() {
        boolean looping = false;
        Object loopClip = null;
        if (looping) {
            loopClip.stop();    //Stop the sound loop.     //<--The error is '.stop'    I need to define this method somewhere?
         }
 }

0
 
LVL 92

Accepted Solution

by:
objects earned 1000 total points
ID: 13799696
should be more like:

    private AudioClip clip = null;
    private boolean looping = false;

    public void start() {

        try {
            clip =
                    java.applet.Applet.newAudioClip(new java.net.URL(
                    getDocumentBase(), "1000Hz.au"));
        } catch (MalformedURLException ex) {
        }

      clip.play( );

    }


    //Stop the applet
    public void stop() {
         if (looping) {
            clip.stop();    //Stop the sound loop.
         }
 }
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month8 days, 11 hours left to enroll

621 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