常见问题

  • 确认手机安卓系统版本在4.1以上,竖屏拍摄只支持android4.1以上版本
  • 确认Activity设置了portrait属性
  • 确认在开始预览和录制之前调用了Manager.forcePortrait(true)来设置竖屏拍摄

从463版本开始只需调用Manager.forcePortrait()以及在AndroidManifest.xml设置相对应的screenOrientation属性即可设置横屏还是竖屏拍摄

使用Manager.getCamera()获取摄像头实例,设置自动聚焦参考代码如下:

//使用SDK获取camera实例
Camera camera = Manager.getCamera();
Camera.Parameters params = camera.getParameters();
//设置为自动聚焦模式
params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
camera.setParameters(params);
//设置摄像头自动聚焦回调,success为true则自动聚焦成功,false则失败
camera.autoFocus(new AutoFocusCallback() {
    @Override
    public void onAutoFocus(boolean success, Camera camera) {

    }
});

使用Manager.getCamera()获取摄像头实例,开启闪光灯需在开启预览的情况下才能打开,打开或关闭闪光灯参考代码如下:

Camera camera = Manager.getCamera();
Parameters parameters = camera.getParameters();
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);//开启闪光灯
parameters.setFlashMode(Parameters.FLASH_MODE_OFF);//关闭闪光灯
camera.setParameters(parameters);

  • connectVS 是通过服务器地址(例如'192.168.1.1')和TCP端口(例如'9998')与服务器建立连接
  • initNet 是通过服务器地址(例如'192.168.1.1')和UDP端口(例如'9999')与服务器建立连接
  • connectCloud 是通过服务器的getVS接口与服务器建立连接,连接直播云的接口地址为http://c.zhiboyun.com/api/20140928/get_vs,连接私有云的接口地址类似于http://192.168.1.1/api/20140928/get_vs

connectVS接受的是服务器地址和TCP端口,用于与私有视频服务器建立连接;initNet接受的是服务器地址和UDP端口,用于与私有视频服务器建立连接;connectCloud接受的是getVS的接口地址,用于与公直播云(私有云)建立连接。

  • 分辨率与码流选择与带宽相匹配的值,否则分辨率和码流设置过高而带宽不够会导致延迟越来越大
  • 打开网络自适应功能,参见setNetWorkingAdaptive

分辨率与码流的对应关系为:分辨率设置为width x height 则码流取值范围为 width/2(Kbit)至width x 1.5(Kbit)之间,一般取为width(Kbit)即可,具体根据网络带宽自行调整。 注意在调用startRecord时传入的bitrate应乘以1024。

该问题是由于设置的视频的分辨率的宽高比与手机屏幕的宽高比不一致所导致的,参考代码如下:

//获取视频预览SurfaceView
mPreview = (SurfaceView) findViewById(R.id.preview_view);
//获取手机屏幕宽高
Display display =  this.getWindowManager().getDefaultDisplay(); 
int screenWidth = display.getWidth();
int screenHeight = display.getHeight();
ViewGroup.LayoutParams lp = mPreview.getLayoutParams();
//横屏拍摄时调用以下代码,其中videoWidth和videoHeight对应视频分辨率的宽和高
lp.width = screenWidth;
lp.height = (int)(lp.width * videoHeight /videoWidth);
//竖屏拍摄时调用以下代码,其中videoWidth和videoHeight对应视频分辨率的宽和高
lp.height = screenHeight;
lp.width = (int)(lp.height * videoHeight /videoWidth);
//最后将LayoutParams设置给视频预览的SurfaceView
mPreview.setLayoutParams(lp);

由于当前SDK onRecordFinished()还待完善,现在你调用stopRecord()后分两种情况去判断 是否可以开启新的直播(录制是否已停止)

  • 当是离线录制时,当回调函数 onLocalFileName() 被回调 说明 当前录制已停止 并在本地生成文件
  • 当是在线直播时,当回调函数 onStreamUpLoaded()被回调 说明 当前直播已停止并已上传完毕

由于直播过程中可能会有电话或者短信以及应用层可能需要在直播时进行分享等等操作,所以我们的SDK在457版本支持了直播的暂停和恢复。

在初始化播放器时传入"-rtsp_transport", "tcp"参数,示例代码如下: player = new Player(getApplication(), handler, fileName, new String[]{"-rtsp_transport", "tcp"});

参考代码如下:

Display display =  this.getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();//全屏的宽
int height = display.getHeight();//全屏的高
ViewGroup.LayoutParams lp = mPreview.getLayoutParams();

if (lp.height == Config.videoHeight) {
    lp.height = height;
    lp.width = width;
} else {
    lp.height = videoHeight;//指定的高
    lp.width =videoWidth;//指定的宽
}
mPreview.setLayoutParams(lp);//mPreview 为预览的SurfaceView

参考代码如下:

//添加设置读写权限:
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
//判断是否屏幕旋转被关闭,如果关闭则打开:
int flag = Settings.System.getInt(getContentResolver(),
    Settings.System.ACCELEROMETER_ROTATION, 0);
if (0 == flag) {
  Settings.System.putInt(getContentResolver(),
      Settings.System.ACCELEROMETER_ROTATION, 1);
 }

参考代码如下:

1.首先 AndroidManifest.xml 不设置Activity的orientation,并设置android:configChanges="orientation|screenSize"(设置该属性横竖屏切换 activity不被销毁)
2.在Activity实现下面回调,同时打开手机自动旋转功能(具体实现参考上一问题代码)
@Override
public void onConfigurationChanged(Configuration newConfig) {
    // TODO Auto-generated method stub
    super.onConfigurationChanged(newConfig);
    if (Manager.getRecordStatus() == Manager.RecordStatus.IDLE) {//在未录制状态
        if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
            Log.e(TAG, "竖屏");
            Manager.stopPreview();
            Manager.forcePortrait(true);
            Manager.startPreview();
        } else {
            Log.e(TAG, "横屏");
            Manager.stopPreview();
            Manager.forcePortrait(false);
            Manager.startPreview();
        }
    } else {
        Toast.makeText(this, "正处于录制状态无法进行横竖屏切换", Toast.LENGTH_LONG).show();
    }
}

-libraryjars libs/hiksdk.jar
-keep class com.hikvision.** {*;}
-dontwarn com.hikvision.hiksdk.*

-libraryjars libs/core.jar
-keep class cn.com.xpai.** {*;}
-keep class org.cnnt.player.** {*;}
-keep class org.libsdl.app.** {*;}
-dontwarn cn.com.xpai.core.*

-keep public class org.cnnt.player.* {
    public <fields>;
    public <methods>;
}

-keep public class org.libsdl.app.SDLActivity {
    public <fields>;
    public <methods>;
}