Solved

Sun.Audio.*;

Posted on 2001-06-18
2
198 Views
Last Modified: 2010-04-16
I want to use the sun.audio.* classes in my applet.
However, I do not want to use: import sun.audio.*;, because not all browsers have the sun.audio.*-classes. Rather I want to use:

try {
  audioStream = Class.forName(sun.audio.AudioStream);
  audioPlayer = Class.forName(sun.audio.AudioPlayer);
}
catch {}

However, when I do this, I can obviously not declare a public variable: public AudioPlayer audioPlayer;, because the package has not yet been imported.

Any suggestions for how to deal with this?
0
Comment
Question by:terjeg
2 Comments
 
LVL 3

Accepted Solution

by:
superschlonz earned 200 total points
ID: 6203735
Create an interface with the needed methods, impement it in a class
which does these audio things like this:

public interface AudioInterface
{
  public void play();
}

public class AudioFacade implements AudioInterface
{
  AudioStream stream;
  AudioPlayer player;
  public AudioFacade()
  {
   stream = new AudioStrem( ... );
   player = new AudioPlayer( ... );
  }
  public void play()
  {
    player.play();
  }
}

and use it like this:

AudioInterface audio = null;
try {
  audio = class.forName( "AudioFacade").newInstance();
} catch( Throwable t ) {
  // could not create...
}
if( audio != null )
{
  audio.play();
}

This way you have no direct reference to the AudioFacade and your applet
doesn't need those classes for beeing loaded.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 8950801


No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


--  points to superschlonz


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 116
web services creation SOAP vs REST 5 56
javap not working 8 58
Opening PDF on button click and fill new document 2 47
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.

856 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