有关在 JME midlet 中播放音频文件的问题
我正在制作一个 midlet,用于播放本地音频文件。显然这是行不通的。在下面显示的代码片段中,我在“is”变量上得到了空引用。
1. try{
2. System.out.println("path: " + this.getClass());
3. InputStream is = this.getClass().getResourceAsStream("res/01Track.wav");
4. p1=Manager.createPlayer(is, "audio");
5. p1.realize();
6. p1.prefetch();
7. p1.start();
8. }
9. catch(Exception e){
10. System.out.println(e.getMessage());
11. }
我认为“this.getClass().getResourceAsStream(“res/01Track.wav”)”位有问题,但我一生都无法弄清楚为什么,并且我尝试引用该文件20种不同的方式。
如果我打印“this.getClass()”,它会给我“路径:class Mp3spiller”。 “01Track.wav”的绝对路径是“E:\Mine dokumenter\Dokumenter\workspace_mobiljava\Mp3spiller\res\01Track.wav”。我认为我应该相对参考“E:\Mine dokumenter\Dokumenter\workspace_mobiljava\Mp3spiller”是完全错误的吗?
如果有人能指出我做错了什么,我将不胜感激。我基本上是从网上找到的教程中窃取了代码,所以我认为它会起作用。
I am making a midlet which is to be used to play out local audio files. It is obviously not working. I am getting a null reference on the "is" variable, in the code snippet shown below.
1. try{
2. System.out.println("path: " + this.getClass());
3. InputStream is = this.getClass().getResourceAsStream("res/01Track.wav");
4. p1=Manager.createPlayer(is, "audio");
5. p1.realize();
6. p1.prefetch();
7. p1.start();
8. }
9. catch(Exception e){
10. System.out.println(e.getMessage());
11. }
I assume there is something wrong with the "this.getClass().getResourceAsStream("res/01Track.wav")" bit, but I can not for the life of me figure out why, and I have tried referring to the file in 20 different ways.
If I printline "this.getClass()" it gives me "path: class Mp3spiller". The absolute path to "01Track.wav" is "E:\Mine dokumenter\Dokumenter\workspace_mobiljava\Mp3spiller\res\01Track.wav". Am I completely wrong in thinking that I should refer relatively to "E:\Mine dokumenter\Dokumenter\workspace_mobiljava\Mp3spiller"?
If anyone could point out what I am doing wrong, I would be grateful. I have basically stolen the code from a tutorial I found online, so I would have thought it would be working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
播放器初始化错误...
第二个参数采用您正在播放的流的 mime 类型。
因此它应该是
p1=Manager.createPlayer(is, "audio/wav");
否则一切看起来都很好......如果您根据以下内容添加了资源文件夹
维瓦特的最后评论。
希望这有帮助...
the player initialization is wrong...
second parameter takes the mime type for the stream you are playing.
hence it should be
p1=Manager.createPlayer(is, "audio/wav");
otherwise everything seems ok... if you have added the resouce folder according to the
Vivart's last comment.
hope this helps...