如何在android中停止后台播放音乐

发布于 2024-12-19 19:20:22 字数 83 浏览 2 评论 0原文

我尝试从 url 流式传输音频,并且工作正常。当我退出应用程序时,该网址也在后台播放。但是当我再次进入我的应用程序时我无法停止它我怎么能停止。感谢帮助。

i tried to stream an audio from url and its working fine. The url is playing on background also when i quit the application. But i cant able to stop it when i enter my app again how could i stop. Help is appreciated.

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

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

发布评论

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

评论(2

慈悲佛祖 2024-12-26 19:20:22

将其放入您的主要活动中(或放置播放器的任何位置):

protected void onPause() {
    super.onPause();
    // Put your media player object here
    mp.pause();
}

每当您离开活动时,音乐就会停止。

Put this in your main activity (or wherever you placed your player):

protected void onPause() {
    super.onPause();
    // Put your media player object here
    mp.pause();
}

That should stop your music whenever you leave your activity.

始于初秋 2024-12-26 19:20:22

在您的 onBackPressed 方法中写入 mp.stop() ,然后写入 mp=null ,其中 mp 是您的媒体播放器实例...

In your onBackPressed method write mp.stop() and then mp=null where mp is your mediaplayer instance...

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