[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 329
  • Last Modified:

play sound in application, again

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
jdaues
Asked:
jdaues
  • 6
  • 5
1 Solution
 
jdauesAuthor Commented:
ok, let's make more interesting...100 points
0
 
heyhey_Commented:
it seems that it's not easy to play sound from application  ...
you can check the JavaSound / JavaMedia packages (www.javasoft.com)

0
 
Dracula112698Commented:
Put again the whole question.
I don't want to search through all.

Dracula
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!

 
jdauesAuthor Commented:
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
 
jdauesAuthor Commented:
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
 
heyhey_Commented:
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
 
jdauesAuthor Commented:
i want my code to work on PC and Mac.
maybe the thing to do is to go to JDB 1.2 ....yikes...

0
 
jdauesAuthor Commented:
JDK 1.2

0
 
heyhey_Commented:
again.

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

best regards
  heyhey
0
 
heyhey_Commented:
so can I lock the question and get the points ?
0
 
heyhey_Commented:
i've invested some time in this question, so I suppose I can lock the question and get the points, Ok ?


0
 
jdauesAuthor Commented:
sorry for the delay
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now