IMSDroid视频横屏显示

集成了IMSdroid 视频通话后,发现双人视频显示为横屏,很纳闷,仔细查看代码,发现做了横竖屏切换的重力感应监听,就是可以发送任意的角度视频。如下:

if (mIsVideoCall) {
			mListener = new OrientationEventListener(this,
					SensorManager.SENSOR_DELAY_NORMAL) {
				@Override
				public void onOrientationChanged(int orient) {
					try {
						if ((orient > 345 || orient < 15)
								|| (orient > 75 && orient < 105)
								|| (orient > 165 && orient < 195)
								|| (orient > 255 && orient < 285)) {
							int rotation = mAVSession.compensCamRotation(true);
							if (rotation != mLastRotation) {
								Log.d(ScreenAV.TAG,
										"Received Screen Orientation Change setRotation["
												+ String.valueOf(rotation)
												+ "]");
								applyCamRotation(rotation);
								if (mSendDeviceInfo && mAVSession != null) {
									final android.content.res.Configuration conf = getResources()
											.getConfiguration();
									if (conf.orientation != mLastOrientation) {
										mLastOrientation = conf.orientation;
										switch (mLastOrientation) {
										case android.content.res.Configuration.ORIENTATION_LANDSCAPE:
											mAVSession
													.sendInfo(
															"orientation:landscape\r\nlang:fr-FR\r\n",
															NgnContentType.DOUBANGO_DEVICE_INFO);
											break;
										case android.content.res.Configuration.ORIENTATION_PORTRAIT:
											mAVSession
													.sendInfo(
															"orientation:portrait\r\nlang:fr-FR\r\n",
															NgnContentType.DOUBANGO_DEVICE_INFO);
											break;
										}
									}
								}
							}
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			};
			if (!mListener.canDetectOrientation()) {
				Log.w(TAG, "canDetectOrientation() is equal to false");
			}
		}

通过分析,双方接收到的视频显示为横屏,应该是对方发送过来的就为横屏,但是我手机设置成竖屏显示了,不可能会进入到横竖屏切换的监听器内部,通过查看视频预览产生类org.doubango.ngn.media.NgnProxyVideoProducer,观察到里面有个方法:

public int compensCamRotation(boolean preview){
		if(mVideoProducer != null){
			return mVideoProducer.compensCamRotation(preview);
		}
		return 0;
	}
	
	public int camRotation(boolean preview){
		if(mVideoProducer != null){
			return mVideoProducer.getNativeCameraHardRotation(preview);
		}
		return 0;
	}
显而易见,应该就是这里处理没错!再深入代码查看:

public int compensCamRotation(boolean preview){

		final int cameraHardRotation = getNativeCameraHardRotation(preview);
		final android.content.res.Configuration conf = NgnApplication.getContext().getResources().getConfiguration();
		if(conf.orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE){
			return 0;
		}

		if (NgnApplication.getSDKVersion() >= 9) {
			if (preview) {
				return cameraHardRotation;
			}
			else{
				switch (cameraHardRotation) {
					case 0:
					case 180:
					default:
						return 0;
					case 90:
					case 270:
						return 90;
				}
			}			
		}
		else {
			int     terminalRotation   = getTerminalRotation();
			int rotation = 0;
			rotation = (terminalRotation-cameraHardRotation) % 360;
			return rotation;
		}
	}

所以,我这边在进入Incall状态后,通过调用:

applyCamRotation(mAVSession.compensCamRotation(true));// 保持视频竖屏(其实用平板的话是会自动横屏显示的)



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值