简体   繁体   English

开始新意图后停止媒体播放器

[英]Stop Media Player After starting new intent

Here's my problem: I start a media player, and if I start a new intent, or leave the app and go back to it..这是我的问题:我启动了一个媒体播放器,如果我开始一个新的意图,或者离开应用程序和 go 回到它..

mp.stop;

..wont work (mp is my media player variable). ..不会工作(mp 是我的媒体播放器变量)。

is there anyway to fix this?有没有什么办法解决这一问题?

Bonus to whoever can tell me how to link it up to a widget.任何人都可以告诉我如何将它链接到一个小部件。

You always must call mp.release() in your Activity's onDestroy() .您始终必须在 Activity 的onDestroy()中调用mp.release() ) 。 It is also recommended to at least call mp.pause() in on onPause() Activity's method.还建议至少在onPause() Activity 的方法中调用mp.pause()

If you want playback to continue outside of Activity lifecycle (after onPause() / onStop() / onDestroy() ) you have to create Service and play audio content from there.如果您希望在 Activity 生命周期之外继续播放(在onPause() / onStop() / onDestroy()之后),您必须创建服务并从那里播放音频内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM