暂停时发生未知错误()

发布于 2024-08-15 12:36:20 字数 1022 浏览 4 评论 0原文

我收到以下错误

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一杯敬自由 2024-08-22 12:36:20

我已经阅读了本教程关于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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文