小程序大小(15 兆字节)太重而无法加载?
我想知道15兆的小程序加载是否很重?
我的主要问题是两个声音文件(.Au),其重量约为 9 兆字节。
有人建议如何使用 mp3 来代替或其他减肥想法吗?
谢谢
相关代码:
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);
}
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
添加 mp3plugin.jar 的 JMF 到小程序的运行时类路径(在存档元素中)和 Java Sound 将能够打开 MP3,就好像它们是 wav 或 au 一样。
MP3 插件将无法解析一些更现代的 MP3,这些 MP3 会执行非标准操作,例如在 MP3 中包含封面艺术,但使用标准 MP3 格式对其进行编码,并且可以正常处理它们。
请注意,我还将
Archive
更改为archive
(只是为了保持一致)和(通常可以容忍,但不正确)更改为
(假设小程序位于
GUI
包)。如果小程序不在 GUI 包中,则应以不同的方式编写该元素。忽略EXE链接并下载Zip!
不必运行/安装 EXE(EXE 对于 Mac 或 Unix/Linux 上的最终用户来说没有用)。只需展开 Zip 并将 Jar 添加到运行时类路径
这将是“问题解决”(对于嵌入式小程序)。
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.
Note that I also changed
Archive
toarchive
(just to keep things consistent) and(generally tolerated, but not correct) to
(which presumes the applet is in the
GUI
package). If the applet is not in the GUI package, the element should be written differently.Ignore the EXE link and download the Zip!
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
That will be 'problem solved' (for the embedded applet).
您可以使用 JLayer 来使用 mp3。
降低小程序大小的一种选择是单独加载音频或流式传输音频,这样您在获取音乐时至少可以有一个加载栏/图像。
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.
查看任何下载时间计算器 — 一个非常好的在线时间超过一分钟。听起来特别沉重。
Check out any download time calculator — it's more than a minute on a very good line. Sounds like extremely heavy.