在 BlackBerry 上播放声音时出现错误
我在编写一个非常小的应用程序来学习如何为 BlackBerry 进行开发时,无法在一个非常小的应用程序中播放一个简短的 MP3 文件。
因为我是 BlackBerry 开发的新手,所以我已将应用程序的 Eclipse 项目上传到 http://因为我不知道问题是否出在我的 Java 编程上,或者我在项目中布置资源的方式,或者其他方面。
这是一个非常小的项目 - 只有一个 Java 文件和一个 Java 文件。三个媒体文件 - 所以请帮助我看看您是否可以在计算机上的 Curve 8520 模拟器中无错误地运行它。 (它是为 8520 设计的,因为这是我的一个朋友的手机;我自己还没有 BB!)
这个想法是,当用户在轨迹球/板上“向下”按下/滚动时,会发出声音将播放,但目前我只收到一条错误消息,而不是声音: javax.microedition.media.MediaException 。
我尝试过对此进行调试,但正如我所说,我是 BB 开发的新手,所以我真的不知道如何理解从我设置的断点中获得的信息。
请你告诉我我哪里错了?
我真的很想在圣诞节前完成这个工作;请帮忙!
预先感谢:)
编辑:这是代码的相关部分,尽可能地精简:
public boolean navigationMovement(int dx, int dy, int status, int time) {
if (dx == 0 && dy == 1)// DOWN
{
makeNoise("growl");
}
return true;
}
private void makeNoise(String action) {
if (action == "growl") {
Dialog.alert("GROWL");
try
{
Player p = javax.microedition.media.Manager.createPlayer("growl.mp3");
p.realize();
VolumeControl volume = (VolumeControl)p.getControl("VolumeControl");
volume.setLevel(30);
p.prefetch();
p.start();
}
catch(MediaException me)
{
Dialog.alert(me.toString());
}
catch(IOException ioe)
{
Dialog.alert(ioe.toString());
}
}
invalidate();
}
进一步编辑 我已经删除了下载项目的链接,因为问题确实出现在代码上,而且现在已经解决了。
I'm having trouble getting a short MP3 file to play in a very small app I'm writing to learn how to develop for the BlackBerry.
Because I'm a newbie at BlackBerry development, I've uploaded my Eclipse project for the app to http://stroke.sampablokuper.com/stroke.zip because I don't know if the problem's with my Java programming, or the way I've laid out the resources in my project, or something else.
It's a very small project - only one Java file & three media files - so please help me by seeing if you can run it without errors in the Curve 8520 simulator on your computer. (It's designed for the 8520, because that's the phone a friend of mine has; I don't have a BB myself - yet!)
The idea is that when the user presses/scrolls "down" on the trackball/pad, a sound will be played, but currently instead of the sound, I just get an error message: javax.microedition.media.MediaException .
I've tried to debug this, but as I say, I'm a total newbie to BB development, so I don't really know how to make sense of the information I get from the breakpoints I've set.
Please can you tell me where I've gone wrong?
I really want to finish this before Christmas; please help!
Thanks in advance :)
EDIT: here's the relevant portion of the code, stripped down as much as possible:
public boolean navigationMovement(int dx, int dy, int status, int time) {
if (dx == 0 && dy == 1)// DOWN
{
makeNoise("growl");
}
return true;
}
private void makeNoise(String action) {
if (action == "growl") {
Dialog.alert("GROWL");
try
{
Player p = javax.microedition.media.Manager.createPlayer("growl.mp3");
p.realize();
VolumeControl volume = (VolumeControl)p.getControl("VolumeControl");
volume.setLevel(30);
p.prefetch();
p.start();
}
catch(MediaException me)
{
Dialog.alert(me.toString());
}
catch(IOException ioe)
{
Dialog.alert(ioe.toString());
}
}
invalidate();
}
Further edit I've removed the link to download the project, since the problem did indeed appear to be with the code, and is now solved anyway.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在 SDCard 上有 mp3 文件,您的 URI 应该是
file:///SDCard/.mp3
但如果您从应用程序中播放它,则getResourceAsStream
是回答if you have mp3 file on SDCard your URI should be
file:///SDCard/<file>.mp3
but if you are playing it from application thengetResourceAsStream
is the answer问题原来是传递给 .createPlayer 方法的字符串需要是 URI。
在最终放弃之前,我沿着
file:///growl.mp3
尝试了许多变体(如果有人知道指向 BlackBerry 应用程序中的文件的正确 URI 语法,请发表评论!)并解决对此:相比之下,它有点粗糙,但至少它有效!
The problem turned out to be that the string passed to the .createPlayer method needs to be a URI.
I tried many variations along the lines
file:///growl.mp3
before eventually giving up (if anyone knows the correct URI syntax for pointing to a file within a BlackBerry App, please comment!) and settling on this:It's a bit crufty by comparison, but at least it works!