Android 上旋转手机可重新启动视频
当我旋转手机时,我的活动将重新启动。我有一个正在播放视频的视频视图,我旋转并重新启动视频。现在我发现将其添加到清单中的活动中修复了它
<activity android:name="Vforum" android:configChanges="orientation"></activity>
现在的问题是视频控件不会被重新绘制,直到它们消失并返回,因此要么留下从横向模式到纵向模式的非常长的控件,要么从横向模式到纵向模式的非常短的控件肖像到风景。一旦它们消失,然后我点击让它们回来,那么它们的大小就正确了。有更好的方法吗?
When I rotate my phone, my Activity restarts. I have a video view playing video, I rotate and the video restarts. Now I found adding this to my activity in the manifest fixed it
<activity android:name="Vforum" android:configChanges="orientation"></activity>
The problem now is the video controls aren't being redrawn until they disappear and come back, thus leaving either really long controls going from landscape to portrait mode or really short controls going from portrait to landscape. Once they disappear and then I tap to make them come back, then they are correctly sized. Is there a better method of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
添加
将
android:configChanges="orientation"
到 AndroidManifest.xml 中的 Activity。
如果您的目标 API 级别为 13 或更高,则除了
orientation
值之外,您还必须包含screenSize
值,如下所述< a href="http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange" rel="noreferrer">此处。所以你的标签可能看起来像add
android:configChanges="orientation"
to your Activity in AndroidManifest.xml.
If your target API level 13 or higher, you must include the
screenSize
value in addition to theorientation
value as described here. So your tag may look like考虑记住活动生命周期事件中的视频文件位置。当 Activity 创建时,您可以获得视频位置并从重新启动时开始播放。
在您的 Activity 类中:
Consider remembering video file position in Activity lifecycle events. When Activity is created you could obtain video position and play it from the moment it was restarted.
In your Activity class:
将
configChanges
属性添加到清单中意味着您将 自己处理配置更改。重写 Activity 中的onConfigurationChanged()
方法:Adding the
configChanges
attribute to your manifest means that you will handle config changes yourself. Override theonConfigurationChanged()
method in your activity:ConfigChanges 是对的,但它确实是这样工作的;
以及活动课中
ConfigChanges is right, but it did work like this;
and also in the Activity Class
你应该尝试这个。转到您的 AndroidManifest.xml 文件,然后粘贴它的标签。
You Should try this. Go to your AndroidManifest.xml file then past it tag.