如何在android中停止后台播放音乐
我尝试从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将其放入您的主要活动中(或放置播放器的任何位置):
每当您离开活动时,音乐就会停止。
Put this in your main activity (or wherever you placed your player):
That should stop your music whenever you leave your activity.
在您的 onBackPressed 方法中写入 mp.stop() ,然后写入 mp=null ,其中 mp 是您的媒体播放器实例...
In your onBackPressed method write mp.stop() and then mp=null where mp is your mediaplayer instance...