Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
228 views
in Technique[技术] by (71.8m points)

How to retain the sip video call when phone rotate(from portrait to landscape and back to potrait) in android

I have an activity using a fragment to display a video call. Currently, I am only displaying the video in portrait mode but I want to make it more user friendly and want that when during a call if the user rotates the phone then the call will continue in landscape mode, and if hold back the phone then vide screen will be back to portrait mode. I read about a screen orientation activity and now add the following configuration for an activity to stop recreate it when the screen rotates:

android:configChanges="orientation|screenSize|keyboardHidden"

in a fragment, I override a onConfigurationChanged method:

private View mVideoView;
    private View mCaptureView;
    
    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        Log.i(TAG, "OnViewCreated");
        CallActivity callActivity = getCallActivity();
        if (callActivity != null) {
            callActivity.forceUpdate();
        }
        super.onViewCreated(view, savedInstanceState);
    }

  

    @SuppressLint("SourceLockedOrientationActivity")
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){
            Log.e("On Config Change","LANDSCAPE");
            getActivity().setRequestedOrientation(
                    ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
        else{
            Log.e("On Config Change","PORTRAIT");
            getActivity().setRequestedOrientation(
                    ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
    }
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.video, container, false);
        final CallActivity callActivity = getCallActivity();

        mVideoView = view.findViewById(R.id.videoSurface);
        mCaptureView = view.findViewById(R.id.videoCaptureSurface);
        callActivity.setVideoWindow(mVideoView);
        callActivity.setPreviewWindow(mCaptureView);
        return view;
    }

Here is the fragment layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <TextureView
            android:visibility="visible"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:id="@+id/videoSurface" />

    <TextureView
            android:id="@+id/videoCaptureSurface"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true" />

So when a call starts while holding a phone in portrait mode, a video show on the screen but when a phone rotates, only a video lost(can hear the audio within a call) and a black screen start showing. Same as if I stats a call in landscape mode it shows the video in landscape mode but on changing of orientation I lost the video.

Can someone point to me what else I am missing here and how I can retain a video in a change of screen orientation?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...