SurfaceView+MediaPlayer

Fluorite cloud video was used in the project last year. There are a lot of source code for the project, and it takes a lot of time to find the useful code, so TODAY I wrote an article to share with you the integration steps, preview function, double click zoom, gesture zoom function and matters to note. The renderings are as follows:

Fluorite development platform address: open.ys7.com/

Click “Document” to enter the fluorite cloud development platform to develop documents.


I. Integration steps:

1. Create an app First, you need to check the Appkey on the Fluorite open Platform website under “Developer Services – My Apps – App Secret Keys”. 2. Install the SDK

dependencies {    compile 'com. Hikvision. Ezviz: ezviz - SDK: 4.5.1' }Copy the code

3. Configure The Android rights

 <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_LOGS"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>Copy the code

4. To configure the build. Gradle

defaultConfig { ... TargetSdkVersion 22// less than 23... ndk { abiFilters"armeabi-v7a"// Supports only 32 bits}}sourceSets {
        main {
            jniLibs.srcDirs = ['libs']}}Copy the code

Note: (1). All so currently provided are 32 bits and can only be referenced in armeabi-v7a, so it needs to be added

ndk {
    abiFilters "armeabi-v7a"// Support only 32 bits}Copy the code

(2). TargetSdkVersion set to 23 or above will crash on android6.0 phones without Permissions because Android6.0 involves Dangerous Permissions. If higher versions are required, Dangerous Permissions need to be handled yourself.

5. Configuration AndroidManifest. XML

<activity
        android:name="com.videogo.main.EzvizWebViewActivity"
        android:screenOrientation="portrait"
        android:configChanges="orientation|keyboardHidden"
    </activity>

 <receiver
       android:name="you_BroadcastReceiver"
       android:exported="false" >
       <intent-filter>
            <action android:name="com.videogo.action.OAUTH_SUCCESS_ACTION" />
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
        </intent-filter>
   </receiver>Copy the code

6. Code initialization is done in Application

/** * ezopensdk. initLib(this, APP_KEY,"");Copy the code

Code confusion go directly to the development documentation, which is omitted here.

7. Important Nouns:


2. Initialization process

1. Initialize sdK-initlib, i.e. in Application.

EZOpenSDK.initLib(this, APP_KEY,"");Copy the code

2. Obtain AccessToken.

EZOpenSDK.getInstance().setAccessToken("The Token value you want to fill in");Copy the code

3. Add the camera equipment you purchased to fluorite Cloud APP. (Add directly through serial number in download APP)

If you want to get design lists and other features during development, please go directly to the fluorite cloud development platform documentation.


## Video playback process and implementation code:

1. Initialize EZPlayer. Call createPlayer of EZOpenSDK. 2. After the preview is played successfully, perform the following operations: Video recording, photo taking, picture flipping, intercom, pso control, sound switch, video picture zooming and dragging progress playback, see EZPlayer of API for details. Among them, device control interface such as cloud console control and lens display function and intercom belong to restricted level interfaces, which should be preferably called by judging device capability set. Device capability set Please view the attribute value of EZDeviceInfo object to determine the specific method. 3. For the intercom function, if a sound output is displayed during the intercom preview, you need to turn off closeSound before starting the intercom preview and turn on openSound after closing the intercom preview. For details, see Demo. 4. SetVideoLevel in EZOpenSDK sets video definition. This adjustment can be set before or after the video is played successfully. After the video is played successfully and the definition is set, stop stopRealPlay and restart startRealPlay to take effect. EZRealPlayConstants.MSG_REALPLAY_PLAY_SUCCESS; b, failure: ezrealplay_success EZRealPlayConstants.MSG_REALPLAY_PLAY_FAIL, check the errorCode for the failed callback, and if it is 400035 (verification code required) and 400036 (verification code error), it will be up to the developer to reenter the authentication password. And call setPlayVerifyCode to set the password, and then restart the playback.

Implements SurfaceView, implements surfaceHolder.callback, implements SurfaceView, implements surfaceHolder.callback, implements SurfaceView, implements SurfaceView, implements surfaceHolder.callback

private SurfaceView mRealPlaySv = null;
private SurfaceHolder mRealPlaySh = null;Copy the code
mRealPlaySh = mRealPlaySv.getHolder();
mRealPlaySh.addCallback(VideoActivity.this);Copy the code
@Override

public void surfaceCreated(SurfaceHolder holder) {

    if(mEZPlayer ! = null) { mEZPlayer.setSurfaceHold(holder); }else {

    }
    mRealPlaySh = holder;
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    if(mEZPlayer ! = null) { mEZPlayer.setSurfaceHold(null); } mRealPlaySh = null; }Copy the code
<SurfaceView
    android:id="@+id/realplay_sv"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:background="@android:color/transparent" />Copy the code

1. Initialize EZPlayer, bind the EZPlayer to the device, and start playing.

mEZPlayer = YourApplication.getOpenSDK().createPlayer(deviceSerial, cameraNo); // Bind device mezPlayer.sethandler (mHandler); mEZPlayer.setSurfaceHold(mRealPlaySh); mEZPlayer.startRealPlay(); // Start playingCopy the code

2. Play the callback

@override public Boolean handleMessage(Message MSG) {// Log."Correction"."true+zong"+msg); Switch (msg.what) {// Play a successful callbackcase EZConstants.EZRealPlayConstants.MSG_REALPLAY_PLAY_SUCCESS:

break;

}

return false;
}Copy the code

3. Video amplification and gesture amplification function

Add setRealPlaySvLayout() to the successful playback callback; Method, the code for the method is as follows:

private void setRealPlaySvLayout() throws InnerException, PlaySDKException {
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    int whdth = dm.widthPixels;
    int height = dm.heightPixels;
    mRealPlayTouchListener.setSacaleRect(Constant.MAX_SCALE, 0, 0, whdth, height);
    setPlayScaleUI(1, null, null);
}Copy the code
private void setPlayScaleUI(float scale, CustomRect oRect, CustomRect curRect) {
    if (scale == 1) {

        try {
            if(mEZPlayer ! = null) { mEZPlayer.setDisplayRegion(false, null, null); } } catch (BaseException e) { // TODO Auto-generated catch block e.printStackTrace(); }}else {

        if (mPlayScale == scale) {
            try {
                if(mEZPlayer ! = null) { mEZPlayer.setDisplayRegion(true, oRect, curRect);
                }
            } catch (BaseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return;
        }
        try {
            if(mEZPlayer ! = null) { mEZPlayer.setDisplayRegion(true, oRect, curRect);
            }
        } catch (BaseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    mPlayScale = scale;
}Copy the code

OnDestory () {onDestory();

@Override
protected void onDestroy() {
    super.onDestroy();
    if (mEZPlayer != null) {
        mEZPlayer.release();
    }

}Copy the code

2. Method of pausing playback

mEZPlayer.stopRealPlay();Copy the code

If what is not clear can add my public number or wechat, I hope to help you.