Dsiner/CommenPlayer

Can not default play in full screen (Landscape)

tkeatkaew opened this issue · 3 comments

When I coding to play in landscape mode:

AndroidManifest

    <activity
        android:name=".MainActivity"
        android:screenOrientation="landscape"
        android:launchMode="singleInstance">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

And in java

@OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EventBus.getDefault().register(this);
setContentView(R.layout.activity_simple);
initView();
initPlayer();
}

private void initView() {
    player = (CommenPlayer) findViewById(R.id.player);
}

private void initPlayer() {
    player.setLive(true);


    player.setOnNetListener(new OnNetListener() {
        @Override
        public void onIgnoreMobileNet() {
            ignoreNet = true;
        }
    }).setOnPlayerListener(new IPlayerListener() {
        @Override
        public void onLoading() {
            player.getControl().setState(ControlLayout.STATE_LOADING);
        }

        @Override
        public void onCompletion(IMediaPlayer mp) {
            player.getControl().setState(ControlLayout.STATE_COMPLETION);
        }

        @Override
        public void onPrepared(IMediaPlayer mp) {
            if (!ignoreNet && NetConstans.NET_STATUS == NetConstans.CONNECTED_MOBILE) {
                player.pause();
                player.getControl().setState(ControlLayout.STATE_MOBILE_NET);
            } else {
                player.getControl().setState(ControlLayout.STATE_PREPARED);
            }
        }

        @Override
        public boolean onError(IMediaPlayer mp, int what, int extra) {
            player.getControl().setState(ControlLayout.STATE_ERROR);
            return false;
        }

        @Override
        public boolean onInfo(IMediaPlayer mp, int what, int extra) {
            return false;
        }

        @Override
        public void onVideoSizeChanged(IMediaPlayer mp, int width, int height, int sarNum, int sarDen) {

        }
    });
    player.play(getResources().getString(R.string.url1));
}
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    EventBus.getDefault().register(this);
    setContentView(R.layout.activity_simple);
    initView();
    initPlayer();

    // Add this like onConfigurationChanged(...)
    ViewGroup.LayoutParams lp = player.getLayoutParams();
    lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
    lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
    player.setLayoutParams(lp);
    if (player != null) {
        Configuration cf = new Configuration();
        cf.orientation = Configuration.ORIENTATION_LANDSCAPE;
        player.onConfigurationChanged(cf);
    }
}

or you can edit R.layout.activity_simple like this:

<com.d.commenplayer.CommenPlayer
    android:id="@+id/player"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorBlack" />

It's work , @Dsiner . Thanks
Almost done for me, How do I change AspectRatio (set manual)
I found player.toggleAspectRatio() but I don't know how it work.
So after work around from jzVideoPlayer that I ever use thery have code like this:

jzVideoPlayerStandard.setVideoImageDisplayType(JZVideoPlayer.VIDEO_IMAGE_DISPLAY_TYPE_FILL_PARENT);

But for CommenPlayer I've got toggleAspectRatio() and setScaleType()
How can I set aspectratio from IjkVideoView

 private static final int[] s_allAspectRatio = {
            IRenderView.AR_ASPECT_FIT_PARENT,
            IRenderView.AR_ASPECT_FILL_PARENT,
            IRenderView.AR_ASPECT_WRAP_CONTENT,
            IRenderView.AR_MATCH_PARENT,
            IRenderView.AR_16_9_FIT_PARENT,
            IRenderView.AR_4_3_FIT_PARENT};

Thanks for advanced.

you can change AspectRatio like this

player.setScaleType(IRenderView.AR_MATCH_PARENT);

MeasureHelper.doMeasure(...) then it work.