简体   繁体   English

Android videoview无法在横向模式下播放

[英]Android videoview doesn't play in landscape mode

I have an activity that play a video with VideoView. 我有一个使用VideoView播放视频的活动。 Video starting in onCreate, and starts only if layout is in portrait mode, after it has started i can change to landscape and video continue to playing correctly. 视频从onCreate开始,并且仅当布局处于纵向模式时才开始,开始后我可以更改为横向,视频可以继续正确播放。

The problem is when starting activity in landscape mode, in this case video doesn't play. 问题是在横向模式下开始活动时,在这种情况下,视频无法播放。

AndroidManifest.xml AndroidManifest.xml中

 <activity
        android:name="...."
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/title_activity_fullscreen_rec"
        android:launchMode="singleTop"
        android:parentActivityName="...." >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="...." />
    </activity>

In onCreate method I simply set videosource and start videoview. 在onCreate方法中,我只需设置videosource并启动videoview。

Then I have: 然后我有:

    @Override
    @SuppressLint("NewApi")
    public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
    }

Add this code after the onCreate Method in your activity. 在您的活动中的onCreate方法之后添加此代码。

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);    
}

@Override
protected void onRestoreInstanceState(Bundle state) {
super.onRestoreInstanceState(state);    
}

please check this. 请检查一下。 tell me if this works ? 告诉我这可行吗?

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

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