Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I rotate libstreaming Video Preview?

I am a noob to android development and I am trying to implement the libstreaming example 3 sample project. Everything works fine except that I haven't been able to change the orientation of the the video preview to prtrait. No matter what settings I change it refuses to rotate and stays in landscape mode. I know that it is possible to achieve portrait orientation because spydroid uses libstreaming and displays in portrait orientation Any help is greatly appreciated.

My relevant code:

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //<--Does Nothing

    // Configures the SessionBuilder
    mSession = SessionBuilder.getInstance()
            .setContext(getApplicationContext())
            .setAudioEncoder(SessionBuilder.AUDIO_AAC)
            .setAudioQuality(new AudioQuality(8000, 16000))
            .setVideoEncoder(SessionBuilder.VIDEO_H264)
            .setSurfaceView(mSurfaceView)
            .setPreviewOrientation(90) //<--Does Nothing
            .setCallback(this)
            .build();
like image 935
B. Money Avatar asked Oct 12 '14 20:10

B. Money


2 Answers

In the example 3 code, it seems the orientation is fixed in the manifest..just leave it out empty (do not even set to portrait)

        <activity
        android:windowSoftInputMode="stateHidden"
        android:name="net.majorkernelpanic.example3.MainActivity"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.DeviceDefault.Wallpaper.NoTitleBar">

This will allow your activity to change orientation.

To force the orientation, add the below lines at the end of onCreate (after selectQuality(); line)

    mSession.setPreviewOrientation(90);
    mSession.configure();
like image 122
ashoke Avatar answered Oct 13 '22 00:10

ashoke


Explore "libstreaming" library then go to:

  1. VideoStream.java class
  2. Find createCamera() method, replace "mCamera.setDisplayOrientation(mOrientation);" with mCamera.setDisplayOrientation(90);
  3. Find updateCamera(), replace "mCamera.setDisplayOrientation(mOrientation);" with "mCamera.setDisplayOrientation(90);"
like image 21
Gent Avatar answered Oct 13 '22 01:10

Gent