Solved

play sound in application, again

Posted on 1998-12-17
12
311 Views
Last Modified: 2008-02-01
i would like to revisit my previous question about playing sound in an application.
i cannot get the example in the previous example to work.
anybody who can give me code like the example that compiles and runs gets the booty.
0
Comment
Question by:jdaues
  • 6
  • 5
12 Comments
 

Author Comment

by:jdaues
ID: 1229681
ok, let's make more interesting...100 points
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1229682
it seems that it's not easy to play sound from application  ...
you can check the JavaSound / JavaMedia packages (www.javasoft.com)

0
 

Expert Comment

by:Dracula112698
ID: 1229683
Put again the whole question.
I don't want to search through all.

Dracula
0
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.

 

Author Comment

by:jdaues
ID: 1229684
well, i didn't think it was easy because i had looked thru about 10 books, none of which had an example, and 2 of which said that it couldn't be done.
Sailwind, however, says the he/she can do it.

(we're talking jdk 1.1.x here. from what i read, jdk1.2 makes it pretty easy)

here is what Sailwind wrote:


    We'll pass in the AudioClip object from the applet to
    the application.

    let's have the application to play the audioclip, we'll call it
    audioPlayer.

    public class audioPlayer extends Frame {

          AudioClip clip;

          // constructor
          audioPlayer(AudioClip clip) {
              this.clip = clip;

              setSize(200,200);
              setVisible(true);
              setOpaque(true);
              show();

              playAudio(clip);
          }

          // method that plays the audio clip
          public void playAudio(clip) {
                // do the playing function with the clip
          }

          public static void main(String[] argv) {
               AudioPlayer ap = new AudioPlayer();
          }      
    }

    Now we'll define the applet that calls this application            

    class AudioApplet extends Applet {

          init() {

               filename = "mymusic.wav";
               URL url = new URL(getCodeBase() + filename);

               AudioClip ac= this.getToolKit.getAudioclip(url);
               AudioPlayer ap = new AudioPlayer(ac);
         }

         public static void main(String[] argv) {
           init();
        }
    }

    And viola. The applet will get the audio clip, and pass it
    to the AudioPlayer application who does the real work.
    This is a pseudocode, so forgive me if I misspelled some
    of the methods. But I'm sure you get the idea. Hope this helps!


0
 

Author Comment

by:jdaues
ID: 1229685
i have discovered from another source that what i may need is in sun.audio.* classes in the JDK.  The AudioDevice class uses mmedia.dll under NT (part of JDK). but i suppose that means its for windows only.

0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1229686
Yes, i was going to suggest using "sun.audio.*" classes. It is where all the real sound related work is done for the Sun's JDK (Windows + Solaris). For Microsofts JVM probably there are some com.microsoft.audio.* classes that have the same functionality.

The problem is that loading of audioclips in applet is processed from the AppletContext. AppletContext is interface.The real class that implements this behaviour is granted from the browser (in NN it is probably sun.audio.AudioClip.class, in IE - com.microsoft.audio.AudioClip.class). So applets work in browser enviroment and browser does the real Audio loading and playing for them (applets can reach this behaviour using getAppletContext()). Applications don't run in browser enviroment. If you want to play sound from application, you can
1.) use some undocumented (and not so platform undependant - JVM implementation specific) features.
2.) use some library that is supposed to work. JavaSoft's API JavaMedia / JavaSound may help you (I haven't used it, but I think that it is 1.1 compatible)

i don't know who is 'Sailwind', but this code is pure rubish (excuse me)
there is no such method (in my JDK at least)
   AudioClip ac= this.getToolKit.getAudioclip(url);
the only way you can get AudioClip (in Applet) is
   AudioClip ac = applet.getAppletContext().getAudioclip(url);

and what is AudioPlayer ???

you can take a look at http://www.experts-exchange.com/Q.10096989 ("Sound in Java applets")it was about applet that plays some other (not .au format) music.
I made some comments that may be interesting for you.

so genarally - you can't
but there are some (partially) workarounds ;-)

hope this helps
  heyhey
0
 

Author Comment

by:jdaues
ID: 1229687
i want my code to work on PC and Mac.
maybe the thing to do is to go to JDB 1.2 ....yikes...

0
 

Author Comment

by:jdaues
ID: 1229688
JDK 1.2

0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1229689
again.

1. have you checked JavaSound (JavaMedia) API - they are probably 1.1 compatible?
2. will I get some points ? :))

best regards
  heyhey
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1229690
so can I lock the question and get the points ?
0
 
LVL 16

Accepted Solution

by:
heyhey_ earned 100 total points
ID: 1229691
i've invested some time in this question, so I suppose I can lock the question and get the points, Ok ?


0
 

Author Comment

by:jdaues
ID: 1229692
sorry for the delay
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This video teaches viewers about errors in exception handling.

827 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