[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

play sound in application, again

Posted on 1998-12-17
12
Medium Priority
?
326 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 

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 300 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

650 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