想起来了,做的过程中遇到一个问题,license一直返回-5,注册失败,原因找到了,
原因:https://cloud.tencent.com/developer/ask/226553,我的测试机型,恰好是Android9.0
注意测试机的版本,如果是大于O就不行了。license的LICENSE_URL给的是http开头,
android O之后默认禁止不安全的http协议,你可以把url的http改成https。。。。。
再或者配置项目支持http。《android:networkSecurityConfig=XXXXXX》
解决办法:
将licenceURL的http:// 改为https://
就可以了
1.效果图
2.官方地址: https://cloud.tencent.com/document/product/454/7873
我也是看着官方文档,一步一步执行,然后就运行成功了,从集成环境到推流成功,大概花了3个小时
3.推流工具:我用的是vlc,怎么使用,怎么下载,请关注我的上篇博客
4.开始集成环境
4.1先看一下,我的项目结构,项目源码地址:https://github.com/wrs13634194612/TenXunRtmpLive
用到了aar和jni中的so和jar文件,直接从官网下载,然后复制就完事了
4.2 app 下的配置:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.1"
defaultConfig {
applicationId "com.example.administrator.testz"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk {
abiFilters "armeabi", "armeabi-v7a"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
implementation(name: 'LiteAVSDK_Professional_6.7.7754', ext: 'aar')
implementation fileTree(dir: 'src/main/jniLibs', include: ['*.jar'])
}
4.3 工程目录下的配置
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
flatDir {
dirs 'libs'
}
jcenter()
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
到这里就差不多配置完了
5.清单文件,申请权限,引用Application配置
6.新建 MApplication
package com.example.administrator.testz;
import android.app.Application;
import android.util.Log;
import com.tencent.rtmp.TXLiveBase;
/**
* Created by wrs on 24/10/2019,下午 6:40
* projectName: Testz
* packageName: com.example.administrator.testz
*/
public class MApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
String licenceURL =请输入licenceURL; // 获取到的 licence url
String licenceKey = 请输入licenceKey; // 获取到的 licence key
TXLiveBase.getInstance().setLicence(this, licenceURL, licenceKey);
TXLiveBase.getInstance().getLicenceInfo(this);
}
}
7.主界面
package com.example.administrator.testz;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import com.tencent.rtmp.TXLiveBase;
import com.tencent.rtmp.TXLivePushConfig;
import com.tencent.rtmp.TXLivePusher;
import com.tencent.rtmp.ui.TXCloudVideoView;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private TXLiveBase mTXLiveBase;
private TXLivePusher mLivePusher;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String sdkver = TXLiveBase.getSDKVersionStr();
Log.e("TAG", "MainActivity: " + sdkver);
TXLivePushConfig mLivePushConfig = new TXLivePushConfig();
mLivePusher = new TXLivePusher(this);
// 一般情况下不需要修改 config 的默认配置
mLivePusher.setConfig(mLivePushConfig);
TXCloudVideoView mPusherView = (TXCloudVideoView) findViewById(R.id.pusher_tx_cloud_view);
mLivePusher.startCameraPreview(mPusherView);
}
//adds popmenu to toolbar
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int menu_id = item.getItemId();
switch (menu_id) {
case R.id.item1_id:
//启动本地摄像头预览
break;
case R.id.item2_id:
String mUrl = 请输入推流地址 //此处填写您的 rtmp 推流地址
int ret = mLivePusher.startPusher(mUrl);
/// 0: 启动成功;-1: 启动失败;-5:license 校验失败
Log.e("TAG", "cf_btn_start_live: " + ret);
break;
case R.id.item3_id:
mLivePusher.stopCameraPreview(true);
break;
case R.id.item4_id:
mLivePusher.stopPusher();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
}
}
menu:
menu_main
布局:
activity_main
然后看日志,返回0表示成功,用vlc播放推流的地址,能接收到推流的数据,表示推流成功
end