Android 完全旋转 -90 度

Android completely rotates -90 degrees

在处理数字标牌项目时,我们必须提供显示纵向图像和视频的能力。虽然图像表现良好,但视频让我们的 Minix Neo x9 播放器做出奇怪的事情。

播放器不仅改变 videoview 或应用程序的旋转,而且整个 android 系统在以纵向模式播放视频后旋转。

AndroidManifest.xml

 <activity
        android:name="com.example"
        android:label="@string/app_name"
        android:theme="@style/FullscreenTheme"
        android:launchMode="singleTask"
        android:stateNotNeeded="true"
        android:screenOrientation="portrait"
        >

fragment_video.xml

<FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/video_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:alpha="0">

<VideoView
    android:id="@+id/video"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"/>

</FrameLayout>

VideoFragment.java

public class VideoFragment extends Fragment {
private final String TAG = VideoFragment.class.toString();

// Container Activity must implement this interface
public interface OnVideoStateListener {
    public void onVideoCompleted(String slideId);
}

private OnVideoStateListener videoStateListener;
private VideoView videoView;
private MediaController mediaController;

public static VideoFragment newInstance(String location,  String slideId) {
    VideoFragment f = new VideoFragment();

    Bundle args = new Bundle();
    args.putString("location", location);
    args.putString("slideId", slideId);
    f.setArguments(args);

    return f;
}

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    Log.d(TAG, "onAttach: " + activity);

    this.mediaController = new MediaController(activity);
    this.mediaController.setVisibility(View.GONE);
    this.mediaController.setAnchorView(videoView);

    try {
        this.videoStateListener = (OnVideoStateListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(
                activity.toString() + " must implement OnVideoStateListener");
    }
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_video, container, false);

    this.videoView = (VideoView)view.findViewById(R.id.video);
    this.videoView.setMediaController(mediaController);

    return view;
}

@Override
public void onDetach() {
    this.videoStateListener = null;

    if(this.videoView.isPlaying()){
        this.videoView.stopPlayback();
    }
    this.videoView.setMediaController(null);
    this.mediaController = null;

    super.onDetach();
}

public void onStart(){
    super.onStart();

    String location = getArguments().getString("location");
    String slideId = getArguments().getString("slideId");

    this.showVideo(location, slideId);
}

private void showVideo(String location, final String slideId){
    Log.d(TAG, "showVideo(slideId=" + slideId + "): location: " + location);

    File videoFile = new File(location);
    if (videoFile.exists()) {
        String absVideoPath = "file://" + videoFile.getAbsolutePath();
        this.videoView.setVideoPath(absVideoPath);
    } else {
        Log.e(TAG, "showVideo: videoFile not found:" + location);
        callbackFinished(slideId);
        return;
    }

    this.videoView.requestFocus();
    this.videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            Log.e(TAG, "showVideo: onError:" + mp);
            callbackFinished(slideId);
            return false;
        }
    });
    this.videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            Log.i(TAG, "showVideo: onPrepared:" + mp);
            mp.seekTo(0);
            mp.setLooping(false);
            mp.start();
        }
    });
    this.videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            Log.i(TAG, "showVideo: onCompletion:" + mp);
            callbackFinished(slideId);
        }
    });
}

private void callbackFinished(String slideId){
    if(videoStateListener != null){
        videoStateListener.onVideoCompleted(slideId);
    }
}

}

有没有人运行以前遇到过这种问题?

已收到硬件供应商的反馈。说这是默认固件中的错误。