preface
Recently, some creative short video apps are popular among young groups, such as Douyin and MUSE, etc. Ali Cloud also timely launched a simple and easy-to-use short video SDK to help developers quickly introduce full-featured creative short video functions at a low cost. This article mainly introduces how to quickly access the three versions of ali Cloud short video SDK (basic version, standard version and professional version). Help developers learn the basics of access as quickly as possible.
This article describes the Aliyun short video SDK version based on
3.4.0
For details about how to change the upgrade interface, see
Ali Cloud short video SDK document.
The sample project code is
Kotlin
Java access is similar.
The body of the
As the access methods of the three versions are almost the same, this article will mainly introduce the access process of the basic version. The standard version and professional version can be accessed based on the basic version, and only the differences will be explained later.
Basic access
1. Introduce AAR and SO
The minimum aar version must be greater than or equal to 4.3SDK Download pageDownload the corresponding version of the SDK, after decompression, willlibs
Under folderQuSdk-RC.aar
Copy to the Android engineering modulelibs
Folder under willjniLibs
Under folderarmeabi-v7a
The folder is also copied to the wholelibs
Under the folder.
The files in the directory after copying are as follows:
Then modify the build.gradle file under the main module of the Android project as follows:
Step1. Modify the source folder of jniLibs;
android {
sourceSets.main {
jniLibs.srcDir "libs"
}
}Copy the code
Step2. Add the LIBS folder to the warehouse;
repositories {
flatDir {
dirs 'libs'
}
}Copy the code
Step3. Increase aar dependencies.
dependencies { implementation(name: 'QuSdk-RC', ext: 'the aar') implementation 'com. Android. Support: appcompat - v7:24.2.1' implementation 'com. Android. Support: design: 24.2.1' Implementation 'com. Google. Code. Findbugs: jsr305:3.0.0' implementation 'com. Making. Bumptech. Glide: glide: 3.7.0' Implementation 'pub. Devrel: easypermissions: 0.2.1' implementation 'com. Squareup. Okhttp3: okhttp: 3.2.0' implementation 'com. Making. Bumptech. Glide: okhttp3 - integration: 1.4.0 @ aar' implementation 'com. Squareup. Okio: okio: 1.12.0' implementation 'com. Google. Code. Gson: gson: 2.8.0'}Copy the code
If this place encounters
java.lang.NoSuchFieldError
Error, can refer to
Short video android FAQTo solve.
2. Initialize the SDK
Select an appropriate SDK initialization time based on the specific project. The Demo project is initialized in the onCreate() method of Applicatioin.
package me.bogerchan.alishortvideodemo
import android.app.Application
import com.aliyun.common.httpfinal.QupaiHttpFinal
/**
* Created by hb.chen on 2018/1/6.
*/
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
System.loadLibrary("QuCore-ThirdParty")
System.loadLibrary("QuCore")
QupaiHttpFinal.getInstance().initOkHttpFinal()
}
}Copy the code
3. Start writing your business logic
Now that you’re actually plugged in, you can refer to the documentation and start using the various apis directly, with the following sample code.
package me.bogerchan.alishortvideodemo import android.Manifest import android.app.Activity import android.content.Intent import android.content.pm.PackageManager import android.os.Bundle import android.support.v4.app.ActivityCompat import android.support.v7.app.AppCompatActivity import android.widget.Toast import com.aliyun.demo.recorder.AliyunVideoRecorder import com.aliyun.struct.common.VideoQuality import com.aliyun.struct.snap.AliyunSnapVideoParam import me.bogerchan.alishortvideodemo.basic.R class MainActivity : AppCompatActivity() { companion object { val REQUEST_CODE_RECORD_VIDEO = 1 val REQUEST_CODE_FOR_PERMISSION = 2 } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) findViewById(R.id.btn_start_record).setOnClickListener { startRecordActivity() } ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO), REQUEST_CODE_FOR_PERMISSION) } private fun startRecordActivity() { val recordParam = AliyunSnapVideoParam.Builder() .setResolutionMode(AliyunSnapVideoParam.RESOLUTION_720P) .setRatioMode(AliyunSnapVideoParam.RATIO_MODE_9_16) .setRecordMode(AliyunSnapVideoParam.RECORD_MODE_AUTO) .setNeedClip(true) .setMaxDuration(10000) .setMinDuration(2000) .setVideQuality(VideoQuality.HD) .setSortMode(AliyunSnapVideoParam.SORT_MODE_MERGE) .build() AliyunVideoRecorder.startRecordForResult(this, REQUEST_CODE_RECORD_VIDEO, recordParam) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) when (requestCode) { REQUEST_CODE_RECORD_VIDEO -> { if (resultCode == Activity.RESULT_OK && data ! = null) { val type = data.getIntExtra(AliyunVideoRecorder.RESULT_TYPE, 0) if (type = = AliyunVideoRecorder RESULT_TYPE_CROP) {Toast. MakeText (this, "type of cutting", Toast.LENGTH_SHORT).show() } else if (type == AliyunVideoRecorder.RESULT_TYPE_RECORD) { Toast.makeText(this, "The file path to" + data. GetStringExtra (AliyunVideoRecorder. OUTPUT_PATH), Toa.length_short).show()}} else if (resultCode == activity.result_canceled) {toa.maketext (this, "User cancels recording ", Toast.LENGTH_SHORT).show() } } } } override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) when (requestCode) { REQUEST_CODE_FOR_PERMISSION -> { grantResults.forEach { if (it == PackageManager. PERMISSION_DENIED) {Toast. MakeText (this, "without permission, Not playing ", toast.length_short). Show () finish() return@forEach}}}}}}Copy the code
Standard access
1. Introduce AAR and SO
The standard version introduces several more files than the base version, and at the same timeaar
The file name is changed. The final copy result is as follows:build.gradle
File modification is the same as basic access, but needs to be connectedaar
Replace the file name with the standard version name.
2. Initialize the SDK
Compared with the basic version, several more SO files need to be loaded. Part of the SO files are optional functions according to the actual situation. For details, you can refer to the ALIyun short video SDK document. Application file reference after access:
package me.bogerchan.alishortvideodemo
import android.app.Application
import com.aliyun.common.httpfinal.QupaiHttpFinal
/**
* Created by hb.chen on 2018/1/6.
*/
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
System.loadLibrary("aliresample")
System.loadLibrary("live-openh264")
System.loadLibrary("QuCore-ThirdParty")
System.loadLibrary("QuCore")
QupaiHttpFinal.getInstance().initOkHttpFinal()
}
}Copy the code
3. Start writing your business logic
Now that you’re actually plugged in, you can refer to the documentation and start using the various apis directly, with the following sample code.
package me.bogerchan.alishortvideodemo import android.Manifest import android.content.pm.PackageManager import android.opengl.GLSurfaceView import android.os.Bundle import android.support.v4.app.ActivityCompat import android.support.v7.app.AppCompatActivity import android.widget.Toast import com.aliyun.recorder.AliyunRecorderCreator import com.aliyun.struct.recorder.CameraType import com.aliyun.struct.recorder.MediaInfo import me.bogerchan.alishortvideodemo.std.R class MainActivity : AppCompatActivity() { companion object { val REQUEST_CODE_FOR_PERMISSION = 1 } private val mRecorder by lazy { AliyunRecorderCreator.getRecorderInstance(this) } private var mCameraType = CameraType.FRONT override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO), REQUEST_CODE_FOR_PERMISSION) initAliyunRecorder() findViewById(R.id.btn_start_record).setOnClickListener { Toast.makeText(this, "Start recording the segment ", Toast.LENGTH_SHORT).show() mRecorder.startRecording() } findViewById(R.id.btn_stop_record).setOnClickListener { Toast.makeText(this, "Stop recording snippets ", Toast.LENGTH_SHORT).show() mRecorder.stopRecording() } findViewById(R.id.btn_finish_record).setOnClickListener { Toast.makeText(this, "End recording ", Toast.LENGTH_SHORT).show() mRecorder.finishRecording() } findViewById(R.id.btn_change_camera_type).setOnClickListener { Toast.makeText(this, "toggle before and after ", Toast.LENGTH_SHORT).show() mRecorder.switchCamera() } } override fun onStart() { super.onStart() mRecorder.startPreview() } override fun onPause() { super.onPause() mRecorder.stopPreview() } override fun onDestroy() { super.onDestroy() AliyunRecorderCreator.destroyRecorderInstance() } private fun initAliyunRecorder() { mRecorder.setDisplayView(findViewById(R.id.glsv_content) as GLSurfaceView) val mediaInfo = MediaInfo() mediaInfo.videoWidth = 800 mediaInfo.videoHeight = 1200 mediaInfo.isHWAutoSize = true mRecorder.setMediaInfo(mediaInfo) mRecorder.setCamera(mCameraType) mRecorder.setOutputPath(externalCacheDir.absolutePath + "/capture.mp4") } override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) when (requestCode) { REQUEST_CODE_FOR_PERMISSION -> { grantResults.forEach { if (it == PackageManager. PERMISSION_DENIED) {Toast. MakeText (this, "without permission, Not playing ", toast.length_short). Show () finish() return@forEach}}}}}}Copy the code
Professional Access
1. Introduce AAR and SO
Compared to the basic version, the pro version introduces several more files in the so file, and at the same timeaar
The file name is changed. The final copy result is as follows:
The build.gradle file is modified in the same way as the basic access, except that the access AAR file name is replaced with the professional version name.
2. Initialize the SDK
Compared with the basic version, several more SO files need to be loaded. Part of the SO files are optional functions according to the actual situation. For details, you can refer to the ALIyun short video SDK document. Application file reference after access:
package me.bogerchan.alishortvideodemo
import android.app.Application
import com.aliyun.common.httpfinal.QupaiHttpFinal
/**
* Created by hb.chen on 2018/1/6.
*/
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
System.loadLibrary("live-openh264")
System.loadLibrary("QuCore-ThirdParty")
System.loadLibrary("QuCore")
System.loadLibrary("FaceAREngine")
System.loadLibrary("AliFaceAREngine")
QupaiHttpFinal.getInstance().initOkHttpFinal()
}
}Copy the code
3. Start writing your business logic
Now that you’re actually plugged in, you can refer to the documentation and start using the various apis directly, with the following sample code.
package me.bogerchan.alishortvideodemo import android.Manifest import android.content.pm.PackageManager import android.opengl.GLSurfaceView import android.os.Bundle import android.support.v4.app.ActivityCompat import android.support.v7.app.AppCompatActivity import android.widget.Toast import com.aliyun.recorder.AliyunRecorderCreator import com.aliyun.struct.recorder.CameraType import com.aliyun.struct.recorder.MediaInfo import me.bogerchan.alishortvideodemo.pro.R class MainActivity : AppCompatActivity() { companion object { val REQUEST_CODE_FOR_PERMISSION = 1 } private val mRecorder by lazy { AliyunRecorderCreator.getRecorderInstance(this) } private var mCameraType = CameraType.FRONT override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO), REQUEST_CODE_FOR_PERMISSION) initAliyunRecorder() findViewById(R.id.btn_start_record).setOnClickListener { Toast.makeText(this, "Start recording the segment ", Toast.LENGTH_SHORT).show() mRecorder.startRecording() } findViewById(R.id.btn_stop_record).setOnClickListener { Toast.makeText(this, "Stop recording snippets ", Toast.LENGTH_SHORT).show() mRecorder.stopRecording() } findViewById(R.id.btn_finish_record).setOnClickListener { Toast.makeText(this, "End recording ", Toast.LENGTH_SHORT).show() mRecorder.finishRecording() } findViewById(R.id.btn_change_camera_type).setOnClickListener { Toast.makeText(this, "toggle before and after ", Toast.LENGTH_SHORT).show() mRecorder.switchCamera() } } override fun onStart() { super.onStart() mRecorder.startPreview() } override fun onPause() { super.onPause() mRecorder.stopPreview() } override fun onDestroy() { super.onDestroy() AliyunRecorderCreator.destroyRecorderInstance() } private fun initAliyunRecorder() { mRecorder.setDisplayView(findViewById(R.id.glsv_content) as GLSurfaceView) val mediaInfo = MediaInfo() mediaInfo.videoWidth = 800 mediaInfo.videoHeight = 1200 mediaInfo.isHWAutoSize = true mRecorder.setMediaInfo(mediaInfo) mRecorder.setCamera(mCameraType) mRecorder.needFaceTrackInternal(true) mRecorder.setOutputPath(externalCacheDir.absolutePath + "/capture.mp4") } override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) when (requestCode) { REQUEST_CODE_FOR_PERMISSION -> { grantResults.forEach { if (it == PackageManager. PERMISSION_DENIED) {Toast. MakeText (this, "without permission, Not playing ", toast.length_short). Show () finish() return@forEach}}}}}}Copy the code
conclusion
FAQ Resolution