diff --git a/PLDroidMediaStreamingDemo/app/build.gradle b/PLDroidMediaStreamingDemo/app/build.gradle index 668f8d8..8befc54 100644 --- a/PLDroidMediaStreamingDemo/app/build.gradle +++ b/PLDroidMediaStreamingDemo/app/build.gradle @@ -2,14 +2,14 @@ apply plugin: 'com.android.application' android { compileSdkVersion 29 - buildToolsVersion '28.0.3' + buildToolsVersion '29.0.3' defaultConfig { applicationId "com.qiniu.pili.droid.streaming.demo" - minSdkVersion 16 + minSdkVersion 18 targetSdkVersion 29 - versionCode 71 - versionName "3.0.1" + versionCode 72 + versionName "3.0.2" } buildTypes { release { @@ -22,17 +22,19 @@ android { dependencies { // 文件选择 jar 包,非必须 implementation 'com.github.angads25:filepicker:1.0.6' - // dns 相关 jar 包,若无需自定义 DNS 配置,则无需依赖 - implementation 'com.qiniu:happy-dns:0.2.16' + // dns 相关 jar 包,必须依赖 + implementation 'com.qiniu:happy-dns:0.2.17' + // 监听应用生命周期,必须依赖 + implementation 'android.arch.lifecycle:extensions:1.1.1' // 扫码相关 jar 包,非必须 implementation 'com.journeyapps:zxing-android-embedded:3.0.2@aar' - implementation 'com.google.zxing:core:3.2.0' + implementation 'com.google.zxing:core:3.3.3' implementation 'com.android.support:appcompat-v7:28.0.0' if (buildWithCameraStreamingLibrary) { implementation project(':library') } else { // 推流 SDK jar 包,为推流 SDK 必须依赖的库 - implementation files('libs/pldroid-media-streaming-3.0.1.jar') + implementation files('libs/pldroid-media-streaming-3.0.2.jar') } } diff --git a/PLDroidMediaStreamingDemo/app/libs/pldroid-media-streaming-3.0.1.jar b/PLDroidMediaStreamingDemo/app/libs/pldroid-media-streaming-3.0.1.jar deleted file mode 100644 index 8f94d3c..0000000 Binary files a/PLDroidMediaStreamingDemo/app/libs/pldroid-media-streaming-3.0.1.jar and /dev/null differ diff --git a/PLDroidMediaStreamingDemo/app/libs/pldroid-media-streaming-3.0.2.jar b/PLDroidMediaStreamingDemo/app/libs/pldroid-media-streaming-3.0.2.jar new file mode 100644 index 0000000..3a8f711 Binary files /dev/null and b/PLDroidMediaStreamingDemo/app/libs/pldroid-media-streaming-3.0.2.jar differ diff --git a/PLDroidMediaStreamingDemo/app/src/main/AndroidManifest.xml b/PLDroidMediaStreamingDemo/app/src/main/AndroidManifest.xml index 4e3287a..5a02f31 100644 --- a/PLDroidMediaStreamingDemo/app/src/main/AndroidManifest.xml +++ b/PLDroidMediaStreamingDemo/app/src/main/AndroidManifest.xml @@ -13,7 +13,7 @@ - + diff --git a/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/StreamingApplication.java b/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/StreamingApplication.java index ec9b901..fe98447 100644 --- a/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/StreamingApplication.java +++ b/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/StreamingApplication.java @@ -6,6 +6,7 @@ import com.qiniu.pili.droid.streaming.StreamingEnv; import com.qiniu.pili.droid.streaming.demo.service.KeepAppAliveService; import com.qiniu.pili.droid.streaming.demo.utils.AppStateTracker; +import com.qiniu.pili.droid.streaming.demo.utils.Util; public class StreamingApplication extends Application { @@ -17,8 +18,10 @@ public void onCreate() { super.onCreate(); /** * init must be called before any other func + * + * 注意:参数 userId 代表用户的唯一标识符,用于区分不同的用户 */ - StreamingEnv.init(getApplicationContext()); + StreamingEnv.init(getApplicationContext(), Util.getUserId(getApplicationContext())); /** * track app background state to avoid possibly stopping microphone recording diff --git a/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/activity/AVStreamingActivity.java b/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/activity/AVStreamingActivity.java index 7a043c3..70e45d9 100644 --- a/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/activity/AVStreamingActivity.java +++ b/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/activity/AVStreamingActivity.java @@ -396,6 +396,15 @@ private void initStreamingManager() { if (mCameraConfig.mIsCustomFaceBeauty) { mMediaStreamingManager.setSurfaceTextureCallback(mSurfaceTextureCallback); } + mMediaStreamingManager.setCameraErrorCallback(new Camera.ErrorCallback() { + @Override + public void onError(int errorCode, Camera camera) { + // 摄像头被其他应用抢占时触发 + if (errorCode == Camera.CAMERA_ERROR_EVICTED) { + Log.e(TAG, "camera was evicted by the other app!"); + } + } + }); mAudioMixer = mMediaStreamingManager.getAudioMixer(); mAudioMixer.setOnAudioMixListener(new OnAudioMixListener() { @@ -885,6 +894,25 @@ public void run() { } }); break; + case START_VIDEO_ENCODER_FAIL: + case VIDEO_ENCODER_ERROR: + case START_AUDIO_ENCODER_FAIL: + case AUDIO_ENCODER_ERROR: + /** + * 当回调 START_VIDEO_ENCODER_FAIL、VIDEO_ENCODER_ERROR、START_AUDIO_ENCODER_FAIL、 + * AUDIO_ENCODER_ERROR 等状态时,代表编码器出现异常,推流已停止,相应资源也已释放, + * 如果需要,可以基于报错的编码器进行重新配置,更新 {@link AVCodecType} 之后,重新开启推流 + */ + mIsStreaming = false; + mStatusMsgContent = getString(R.string.string_state_ready); + runOnUiThread(new Runnable() { + @Override + public void run() { + mControlFragment.setShutterButtonPressed(false); + Toast.makeText(AVStreamingActivity.this, "编码器错误!!!", Toast.LENGTH_SHORT).show(); + } + }); + break; case IOERROR: /** * 在 `startStreaming` 时,如果网络不可用,则会回调此状态 @@ -972,7 +1000,7 @@ public boolean onRecordAudioFailedHandled(int code) { public boolean onRestartStreamingHandled(int code) { Log.i(TAG, "onRestartStreamingHandled"); startStreamingInternal(2000); - return false; + return true; } /** diff --git a/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/activity/ImportStreamingActivity.java b/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/activity/ImportStreamingActivity.java index 4b4e503..19d0c15 100644 --- a/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/activity/ImportStreamingActivity.java +++ b/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/activity/ImportStreamingActivity.java @@ -6,7 +6,6 @@ import android.os.Bundle; import android.os.Handler; import android.os.HandlerThread; -import android.os.Looper; import android.util.Log; import android.view.SurfaceView; import android.view.View; @@ -392,6 +391,24 @@ public void onStateChanged(StreamingState streamingState, Object extra) { case UNAUTHORIZED_PACKAGE: mLogContent += "Unauthorized package\n"; break; + case START_VIDEO_ENCODER_FAIL: + case VIDEO_ENCODER_ERROR: + case START_AUDIO_ENCODER_FAIL: + case AUDIO_ENCODER_ERROR: + /** + * 当回调 START_VIDEO_ENCODER_FAIL、VIDEO_ENCODER_ERROR、START_AUDIO_ENCODER_FAIL、 + * AUDIO_ENCODER_ERROR 等状态时,代表编码器出现异常,推流已停止,相应资源也已释放, + * 如果需要,可以基于报错的编码器进行重新配置,更新 {@link AVCodecType} 之后,重新开启推流 + */ + mStatusMsgContent = getString(R.string.string_state_ready); + setShutterButtonEnabled(true); + runOnUiThread(new Runnable() { + @Override + public void run() { + Toast.makeText(ImportStreamingActivity.this, "编码器错误!!!", Toast.LENGTH_SHORT).show(); + } + }); + break; } runOnUiThread(new Runnable() { @Override diff --git a/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/utils/Config.java b/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/utils/Config.java index 43a3771..53411dd 100644 --- a/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/utils/Config.java +++ b/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/utils/Config.java @@ -16,4 +16,7 @@ public class Config { public static final String PUBLISH_URL = "PUBLISH_URL"; public static final String TRANSFER_MODE_QUIC = "TRANSFER_MODE_QUIC"; public static final String AUDIO_CHANNEL_STEREO = "AUDIO_CHANNEL_STEREO"; + + public static final String SP_NAME = "PLDroidMediaStreamingDemo"; + public static final String KEY_USER_ID = "userId"; } diff --git a/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/utils/PermissionChecker.java b/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/utils/PermissionChecker.java index 9a16311..6cd38d5 100644 --- a/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/utils/PermissionChecker.java +++ b/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/utils/PermissionChecker.java @@ -56,8 +56,14 @@ public boolean checkPermission() { if (!addPermission(permissionsList, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { permissionsNeeded.add("Write external storage"); } + if (!addPermission(permissionsList, Manifest.permission.READ_PHONE_STATE)) { + permissionsNeeded.add("Read phone state"); + } + if (!addPermission(permissionsList, Manifest.permission.ACCESS_FINE_LOCATION)) { + permissionsNeeded.add("Access fine location"); + } - if (permissionsNeeded.size() > 0) { + if (!permissionsNeeded.isEmpty()) { // Need Rationale String message = "You need to grant access to " + permissionsNeeded.get(0); for (int i = 1; i < permissionsNeeded.size(); i++) { diff --git a/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/utils/Util.java b/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/utils/Util.java index bf7a7b0..6a1bc2e 100644 --- a/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/utils/Util.java +++ b/PLDroidMediaStreamingDemo/app/src/main/java/com/qiniu/pili/droid/streaming/demo/utils/Util.java @@ -2,6 +2,7 @@ import android.app.Activity; import android.content.Context; +import android.content.SharedPreferences; import android.os.Build; import android.widget.Toast; @@ -17,6 +18,7 @@ import java.net.HttpURLConnection; import java.net.InetAddress; import java.net.URL; +import java.util.Random; public class Util { @@ -87,4 +89,21 @@ public static DnsManager getMyDnsManager(Context context) { } return new DnsManager(NetworkInfo.normal, new IResolver[]{r0, r1, r2}); } + + public static String getUserId(Context context) { + SharedPreferences preferences = context.getSharedPreferences(Config.SP_NAME, Context.MODE_PRIVATE); + String userId = preferences.getString(Config.KEY_USER_ID, ""); + if ("".equals(userId)) { + userId = userId(); + SharedPreferences.Editor editor = preferences.edit(); + editor.putString(Config.KEY_USER_ID, userId); + editor.apply(); + } + return userId; + } + + private static String userId() { + Random r = new Random(); + return System.currentTimeMillis() + "" + r.nextInt(999); + } } diff --git a/PLDroidMediaStreamingDemo/app/src/main/jniLibs/arm64-v8a/libpldroid_streaming_core.so b/PLDroidMediaStreamingDemo/app/src/main/jniLibs/arm64-v8a/libpldroid_streaming_core.so index f36cfba..b880ee3 100755 Binary files a/PLDroidMediaStreamingDemo/app/src/main/jniLibs/arm64-v8a/libpldroid_streaming_core.so and b/PLDroidMediaStreamingDemo/app/src/main/jniLibs/arm64-v8a/libpldroid_streaming_core.so differ diff --git a/PLDroidMediaStreamingDemo/app/src/main/jniLibs/armeabi-v7a/libpldroid_streaming_core.so b/PLDroidMediaStreamingDemo/app/src/main/jniLibs/armeabi-v7a/libpldroid_streaming_core.so index 3c4f704..be2a2b8 100755 Binary files a/PLDroidMediaStreamingDemo/app/src/main/jniLibs/armeabi-v7a/libpldroid_streaming_core.so and b/PLDroidMediaStreamingDemo/app/src/main/jniLibs/armeabi-v7a/libpldroid_streaming_core.so differ diff --git a/PLDroidMediaStreamingDemo/app/src/main/jniLibs/armeabi/libpldroid_streaming_core.so b/PLDroidMediaStreamingDemo/app/src/main/jniLibs/armeabi/libpldroid_streaming_core.so index e285e32..703880c 100755 Binary files a/PLDroidMediaStreamingDemo/app/src/main/jniLibs/armeabi/libpldroid_streaming_core.so and b/PLDroidMediaStreamingDemo/app/src/main/jniLibs/armeabi/libpldroid_streaming_core.so differ diff --git a/PLDroidMediaStreamingDemo/app/src/main/jniLibs/x86/libpldroid_streaming_core.so b/PLDroidMediaStreamingDemo/app/src/main/jniLibs/x86/libpldroid_streaming_core.so index bf7c271..3a1015c 100755 Binary files a/PLDroidMediaStreamingDemo/app/src/main/jniLibs/x86/libpldroid_streaming_core.so and b/PLDroidMediaStreamingDemo/app/src/main/jniLibs/x86/libpldroid_streaming_core.so differ diff --git a/README.md b/README.md index 16b8615..3cfa8ff 100644 --- a/README.md +++ b/README.md @@ -39,15 +39,19 @@ PLDroidCameraStreaming 是一个适用于 Android 的 RTMP 直播推流 SDK, ## 设备以及系统要求 - 设备要求:搭载 Android 系统的设备 -- 系统要求:Android 4.0.3(API 15) 及其以上 +- 系统要求:Android 4.3(API 18) 及其以上 ## 版本升级须知 +### v3.0.2 +- 从 v3.0.2 版本开始,请务必添加 `android.arch.lifecycle:extensions:x.y.z` 的依赖 +- 从 v3.0.2 版本开始,`StreamingEnv.init(Context context)` 已被弃用,请更新到 `StreamingEnv.init(Context contex, String userId)` 进行环境的初始化,其中,userId 代表用户的唯一标识符,用于区分不同的用户 + ### v3.0.1 -- 从 3.0.1 版本开始,如果您使用了 Happy DNS 库,建议升级到 0.2.16 版本 +- 从 v3.0.1 版本开始,如果您使用了 Happy DNS 库,请务必升级到 0.2.17 版本 ### v3.0.0 -- **从 v3.0.0 版本开始,七牛直播推流 SDK 需要先获取授权才能使用。授权分为试用版和正式版,可通过 400-808-9176 转 1 号线联系七牛商务咨询,或者 [通过工单](https://support.qiniu.com/?ref=developer.qiniu.com) 联系七牛的技术支持。** +- **从 v3.0.0 版本开始,七牛直播推流 SDK 需要先获取授权才能使用。授权分为试用版和正式版,可通过 400-808-9176 转 2 号线联系七牛商务咨询,或者 [通过工单](https://support.qiniu.com/?ref=developer.qiniu.com) 联系七牛的技术支持。** - **v3.0.0 之前的版本不受影响,请继续放心使用。** - **老客户升级 v3.0.0 版本之前,请先联系七牛获取相应授权,以免发生鉴权不通过的现象。** - 基于 114 dns 解析的不确定性,使用该解析可能会导致解析的网络 ip 无法做到最大的优化策略,进而出现推流质量不佳的现象。因此建议使用非 114 dns 解析 diff --git a/ReleaseNotes/release-notes-3.0.2.md b/ReleaseNotes/release-notes-3.0.2.md new file mode 100644 index 0000000..f07a526 --- /dev/null +++ b/ReleaseNotes/release-notes-3.0.2.md @@ -0,0 +1,35 @@ +# PLDroidMediaStreaming Release Notes for 3.0.2 + +本次更新: + +## 版本 + +- 发布 pldroid-media-streaming-3.0.2.jar +- 更新 libpldroid_streaming_core.so + +## 功能 + +- 新增摄像头抢占回调 +- 新增编码器异常状态回调 + +## 优化 + +- 优化录屏场景下可能出现的帧率较低的问题 + +## 缺陷 + +- 修复音视频和纯音频模式动态切换失败的问题 +- 修复个别机型推流画面变形的问题 +- 修复添加贴纸预览和播放效果不一致的问题 +- 修复软编场景实时刷新水印存在的闪烁问题 +- 修复特殊场景下偶现的 ANR 问题 +- 修复特殊场景下的崩溃问题 + +## 注意事项 + +- **从 v3.0.2 版本开始,请务必添加 `android.arch.lifecycle:extensions:x.y.z` 的依赖** +- 从 v3.0.2 版本开始,`StreamingEnv.init(Context context)` 已被弃用,请更新到 `StreamingEnv.init(Context contex, String userId)` 进行环境的初始化,其中,userId 代表用户的唯一标识符,用于区分不同的用户 +- 从 v3.0.1 版本开始,Happy DNS 库请务必升级到 0.2.17 版本 +- **从 v3.0.0 版本开始,七牛直播推流 SDK 需要先获取授权才能使用。授权分为试用版和正式版,可通过 400-808-9176 转 2 号线联系七牛商务咨询,或者 [通过工单](https://support.qiniu.com/?ref=developer.qiniu.com) 联系七牛的技术支持。** +- **v3.0.0 之前的版本不受影响,请继续放心使用。** +- **老客户升级 v3.0.0 版本之前,请先联系七牛获取相应授权,以免发生鉴权不通过的现象。** \ No newline at end of file diff --git a/releases/arm64-v8a/libpldroid_streaming_core.so b/releases/arm64-v8a/libpldroid_streaming_core.so index f36cfba..b880ee3 100755 Binary files a/releases/arm64-v8a/libpldroid_streaming_core.so and b/releases/arm64-v8a/libpldroid_streaming_core.so differ diff --git a/releases/armeabi-v7a/libpldroid_streaming_core.so b/releases/armeabi-v7a/libpldroid_streaming_core.so index 3c4f704..be2a2b8 100755 Binary files a/releases/armeabi-v7a/libpldroid_streaming_core.so and b/releases/armeabi-v7a/libpldroid_streaming_core.so differ diff --git a/releases/armeabi/libpldroid_streaming_core.so b/releases/armeabi/libpldroid_streaming_core.so index e285e32..703880c 100755 Binary files a/releases/armeabi/libpldroid_streaming_core.so and b/releases/armeabi/libpldroid_streaming_core.so differ diff --git a/releases/pldroid-media-streaming-3.0.1.jar b/releases/pldroid-media-streaming-3.0.1.jar deleted file mode 100644 index 8f94d3c..0000000 Binary files a/releases/pldroid-media-streaming-3.0.1.jar and /dev/null differ diff --git a/releases/pldroid-media-streaming-3.0.2.jar b/releases/pldroid-media-streaming-3.0.2.jar new file mode 100644 index 0000000..3a8f711 Binary files /dev/null and b/releases/pldroid-media-streaming-3.0.2.jar differ diff --git a/releases/x86/libpldroid_streaming_core.so b/releases/x86/libpldroid_streaming_core.so index bf7c271..3a1015c 100755 Binary files a/releases/x86/libpldroid_streaming_core.so and b/releases/x86/libpldroid_streaming_core.so differ