Solved

play sound in application, again

Posted on 1998-12-17
12
299 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
Comment Utility
ok, let's make more interesting...100 points
0
 
LVL 16

Expert Comment

by:heyhey_
Comment Utility
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
Comment Utility
Put again the whole question.
I don't want to search through all.

Dracula
0
 

Author Comment

by:jdaues
Comment Utility
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
Comment Utility
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_
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:jdaues
Comment Utility
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
Comment Utility
JDK 1.2

0
 
LVL 16

Expert Comment

by:heyhey_
Comment Utility
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_
Comment Utility
so can I lock the question and get the points ?
0
 
LVL 16

Accepted Solution

by:
heyhey_ earned 100 total points
Comment Utility
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
Comment Utility
sorry for the delay
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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 …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now