setLoopCount(-1) 时黑莓无法停止音频;
我有以下代码:
InputStream stream = (InputStream)this.getClass().getResourceAsStream("/preview.mp3");
Player p = Manager.createPlayer(stream, "audio/mpeg");
p.realize();
p.prefetch();
p.setLoopCount(-1);
VolumeControl volume = (VolumeControl) p.getControl("VolumeControl");
volume.setLevel(1);
p.start();
然后,当我调用 stopAlarm()
// Stop playing music
void stopAlarm()
{
try
{
// Tell player to stop playing
p.stop();
}
catch (Exception e)
{
Dialog.alert("Error stopping music");
}
// Then release the data and close out the player
p.deallocate();
p.close();
}
简而言之,它不会停止音频。
如果有人能帮助我解决这个问题,我将不胜感激。
I have the following code:
InputStream stream = (InputStream)this.getClass().getResourceAsStream("/preview.mp3");
Player p = Manager.createPlayer(stream, "audio/mpeg");
p.realize();
p.prefetch();
p.setLoopCount(-1);
VolumeControl volume = (VolumeControl) p.getControl("VolumeControl");
volume.setLevel(1);
p.start();
Then when I call stopAlarm()
// Stop playing music
void stopAlarm()
{
try
{
// Tell player to stop playing
p.stop();
}
catch (Exception e)
{
Dialog.alert("Error stopping music");
}
// Then release the data and close out the player
p.deallocate();
p.close();
}
In short, it doesn't stop the audio.
I would be very grateful if someone could help me out on this one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个
Try this
在停止播放器之前,首先检查播放器对象“p”是否为空。
就像
如果玩家对象为空那么我猜你正在将玩家对象创建为本地对象。
因此创建玩家对象
并定义类级别玩家变量。
first check player object 'p' is null or not before stopping the player.
like
if player object is null then i guess you are creating the player object as a local.
so create player object like
and define the class level player variable.
感谢 Vivek,我注意到一个非常小的错误导致它无法工作。一如既往,这非常简单。
虽然 Player 被定义为类级别变量:
问题当然是以下,导致冲突:
所以现在的代码是:
当然要停止它,我只是使用:
Thanks to Vivek, I noticed a very small mistake which prevented this from working. As always, it was extremely simple.
Although Player was defined as a Class level variable:
the problem was of course the following, causing a conflict:
So now the code is:
Of course to stop it, I simply used: