Applet size (15 megabytes) too heavy to load?

笑着哭i 提交于 2019-12-12 19:11:59

问题


I would like to know whether 15 mega is quite heavy applet to load?
My main problem are two sound files(.Au) that its weight is about 9 mega bytes.
Anybody has suggestion of how to use mp3 maybe instead or other ideas of reducing weight?
Thanks

Relevant code:

   public class DJ 
    {

        private ArrayList<Clip> m_Records = new ArrayList<Clip>();
        private int m_CurrentRecored = 0;
        private Thread m_MusicThread = null;
        private AppletContext m_AppletContext;
        //java.net.URL m_CodeBase;
        //AppletContext ac;

        public DJ() 
        {
            try 
            {
                createClip(getClass().getResourceAsStream("/Music/train.mp3"));
                createClip(getClass().getResourceAsStream("/Music/machine.mp3"));
            }
            catch (Exception ex)
            {
                Logger.getLogger(DJ.class.getName()).log(Level.SEVERE, null, ex);
            }

        }

        private void createClip(java.io.InputStream i_SoundFileStream) throws Exception
        {

            InputStream i = new AudioStream(i_SoundFileStream);

            AudioInputStream sound = AudioSystem.getAudioInputStream(i);
            // load the sound into memory (a Clip)
            DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());
            Clip clip = (Clip) AudioSystem.getLine(info);
            clip.open(sound);
            m_Records.add(clip);
        }

回答1:


Anybody has suggestion of how to use mp3 maybe instead ..

Add the mp3plugin.jar of the JMF to the run-time class-path of the applet (in the archive element) and Java Sound will be able to open the MP3s as though they were a wav or au.

The MP3 plugin will not be able to parse some of the more modern MP3s that do non-standard things like including cover art in the MP3, but encode them using a standard MP3 format and it will handle them OK.


..what did you mean to add the mp3plugin.jar to the run time class path of the applet (in the archive element)?

<HTML> 
<BODY> 
<APPLET 
    archive="MyGame.jar,mp3plugin.jar" 
    code="GUI.JPanelGameApplet" 
    width=800 
    height=580>
</APPLET> 
</P> 
</BODY> 
</HTML>

Note that I also changed Archive to archive (just to keep things consistent) and

code="GUI/JPanelGameApplet.class"

(generally tolerated, but not correct) to

code="GUI.JPanelGameApplet" 

(which presumes the applet is in the GUI package). If the applet is not in the GUI package, the element should be written differently.


I've downloaded the MP3 plugin in the exe format ..

Ignore the EXE link and download the Zip!

..I installed it"

Don't bother to run/install the EXE (an EXE is no use to end users on Mac. or Unix/Linux). Just expand the Zip and add the Jar to the run-time class-path

I'll definitely do that code changes in the HTML..

That will be 'problem solved' (for the embedded applet).




回答2:


You could use JLayer for using mp3's.

One option to lower your applet size is load the audio separately or stream it, that way you can at least have a loading bar/image while it's getting the music.




回答3:


Check out any download time calculator — it's more than a minute on a very good line. Sounds like extremely heavy.



来源:https://stackoverflow.com/questions/7828708/applet-size-15-megabytes-too-heavy-to-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!