Android 服务的快速小解释?

发布于 2024-12-26 17:10:49 字数 362 浏览 0 评论 0原文

如果这是一个非常明显的问题,我预先表示歉意,因为我很确定我想得太多了。

不管怎样,我正在 Android 中构建一个音乐播放器,它基本上从 8Tracks 流式传输播放列表,据我所知,这里的最佳实践是使用前台服务。我已经构建了所有内容,并且它完全正常运行,没有服务,但是,我对如何实现该服务有点困惑。

现在,我有我的 Player 类,它控制 MediaPlayer,扩展 Service,但我不太确定从哪里开始。我尝试将它绑定到我的 Engine 类,该类可以协调所有后台工作与 UI,但是我不断收到 ServiceConnectionLeaked 异常,并且我相当确定这只是错误的方法。

我将不胜感激任何帮助;我真正需要的就是朝正确方向点头。感谢您抽出时间!

I apologize up-front if this is a really obvious question since I'm pretty sure I'm over-thinking it.

Anyway, I'm building a music player in Android which basically streams playlists from 8Tracks and, as my understanding is, the best-practice here would be using a foreground service. I've already built everything and it's completely functional sans service, however, I'm a little confused as to how to implement the service.

As is, I have my Player class, which controls the MediaPlayer, extending Service but I'm not quite sure where to progress from there. I've tried binding it to my Engine class which reconciles all the background work with the UI, however I keep getting a ServiceConnectionLeaked exception, and I'm fairly certain this is simply the wrong approach.

I would appreciate any help at all; really a nod in the right direction is all I need. Thanks for your time!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

殤城〤 2025-01-02 17:10:49

我认为您可以直接控制 MediaPlayer 而无需额外的 Player 类。据我所知 MediaPlayer 已经是一项服务,因此您可以使用启动和停止方法来播放某些内容。

I think that you can directly control MediaPlayer without additional Player class. As I know MediaPlayer is already a service so you can use start and stop methods to play something.

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