暂停时发生未知错误()
我收到以下错误
12-15 16:54:37.125: 错误/MediaPlayer(6032): 错误 (-2147483648, 0)
12-15 16:54:37.125: ERROR/MediaPlayer(6032):尝试在服务中执行此代码时
MediaPlayer mp = null;
@Override
public void onCreate() {
if (mp == null) {
mp = new MediaPlayer();
}
}
@Override
public void onStart(Intent intent, int startId) {
if (!mp.isPlaying()) {
Log.d(DEBUG_TAG, "Not playing, starting stream...");
try {
mp.setDataSource(getString(R.string.address_p3));
mp.prepare();
} catch (IOException e) {}
mp.start();
} else {
Log.d(DEBUG_TAG, "Playing, pausing stream...");
try { mp.pause(); }
catch (Exception e) {}
}
}
首次调用服务且没有 MediaPlayer-object
存在,流已正确启动。
但是,当再次调用 onStart() 方法(播放器流式传输)时,我收到上述错误代码。
我找不到有关此错误代码的任何信息,因此我向您寻求帮助。将 mp.pause()
替换为 mp.stop()
即可使其工作。
难道是流不支持暂停?它是 SDP 格式的在线广播流 (RTSP)。
I get the following error
12-15 16:54:37.125: ERROR/MediaPlayer(6032): error (-2147483648, 0)
when trying to execute this code in a service:
MediaPlayer mp = null;
@Override
public void onCreate() {
if (mp == null) {
mp = new MediaPlayer();
}
}
@Override
public void onStart(Intent intent, int startId) {
if (!mp.isPlaying()) {
Log.d(DEBUG_TAG, "Not playing, starting stream...");
try {
mp.setDataSource(getString(R.string.address_p3));
mp.prepare();
} catch (IOException e) {}
mp.start();
} else {
Log.d(DEBUG_TAG, "Playing, pausing stream...");
try { mp.pause(); }
catch (Exception e) {}
}
}
When the service is first called and no MediaPlayer-object
exists, the stream is started correctly.
But when the onStart()
-method is called again (with the player streaming) I get the above error code.
I can't find any information about this error code, so I turn to you for help. Replacing mp.pause()
with mp.stop()
makes it work.
Could it be that the stream does not support pausing? It's an online radio stream (RTSP) in the SDP format.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经阅读了本教程关于Android的博主自定义StreamingMediaPlayer类,在教程中他谈到了他如何完成暂停流。
这可能对您有帮助,如果它不能解决您的需求,至少它为您提供了如何完成此类任务的另一种视角。
I have read this tutorial about the bloggers custom StreamingMediaPlayer class for Android, in the tutorial he talks about how he accomplishes pausing a stream.
This could be helpful for you, if it doesn't solve what you need at least it gives you another perspective on how to achieve such a task.