安卓:保持活动的屏幕方向升级过程中的MediaPlayer运行 [英] Android: Keep MediaPlayer running during Activity screen orientation update
问题描述
我用的MediaPlayer播放的MP3。通过使用目前我禁用屏幕方向变化
I use a MediaPlayer to play an MP3. Currently I disabled screen orientation changes by using
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation"
在清单中。我想现在支持横向模式 - 即删除了这些标签 - 但问题是,破坏/创建周期内的球员被停止,然后重新启动。这是正常的,我真正做到这一点,即使在手动的onPause()
停止播放时,活动进入后台。
in the manifest. I do want to support landscape mode now - i.e. removed those tags - but have the problem that during the destroy/create cycle the player gets stopped and then restarted. This is okay and I actually do this even manually in onPause()
to stop the player when the activity goes in the background.
要保持它在运行过程中的方向现在改变,我试图使其静态的(和使用应用程序上下文一次创建它)。当然,当我删除的onPause的
现在,它确实是我想要的 - 好了,,直到的活动进入后台。 player.stop()
()
To keep it running during orientation changes now, I tried making it static (and using the Application Context to create it once). Of course, when I remove the player.stop()
in onPause()
now, it does what I want - well, until the Activity goes in the background.
于是,两个问题:
- 如何确定活动将被调用后直接重新创建
的onStop()
- 或者:我怎样才能在该周期保持
的MediaPlayer
运行,但停止时,应用程序进入后台
- How can I determine if the Activity will be recreated directly after the call to
onStop()
- Or: How can I keep the
MediaPlayer
running during that cycle, yet stop it when the App goes in the background?
推荐答案
你看使用<一个href="http://developer.android.com/reference/android/app/Activity.html#onConfigurationChanged%28android.content.res.Configuration%29"相对=nofollow> onConfigurationChanged()回调来处理一些这种逻辑?
Have you looked at using the onConfigurationChanged() callback to handle some of this logic?
这篇关于安卓:保持活动的屏幕方向升级过程中的MediaPlayer运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!