Skip to content

Commit 0571e4b

Browse files
committed
update apk download url
1 parent 8cc2bbd commit 0571e4b

File tree

12 files changed

+75
-42
lines changed

12 files changed

+75
-42
lines changed

Prj-Android/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
<img src="https://img.shields.io/badge/NDK-20.0.5594570-lightgrey">
66
</p>
77

8+
## 快速体验🔜
9+
10+
点击下载[Apk](https://www.pgyer.com/qxPXQJiY)
11+
12+
<img src="https://www.pgyer.com/app/qrcode/qxPXQJiY">
13+
14+
815
## Run
916

1017
下载本工程,使用 AndroidStudio 打开之前,需要下载 webRTC,ffmpeg库。

Prj-Android/app/src/main/java/io/anyrtc/liveplayer/PullActivity.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ class PullActivity : AppCompatActivity() {
149149
player.startPlay(url)
150150
binding.run {
151151
binding.btnExit.setOnClickListener {
152-
player.stopPlay()
153152
ArLiveEngine.release()
154153
finish()
155154
}
@@ -172,7 +171,6 @@ class PullActivity : AppCompatActivity() {
172171
}
173172

174173
override fun onBackPressed() {
175-
player.stopPlay()
176174
ArLiveEngine.release()
177175
finish()
178176
}

Prj-Android/app/src/main/java/io/anyrtc/liveplayer/PushActivity.kt

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ class PushActivity : BaseActivity() {
124124
binding.run {
125125
tvUrl.text = pushUrl
126126
ivExit.setOnClickListener {
127-
pusher.stopPush()
127+
if (pushType==2){
128+
ScreenShareKit.stop()
129+
}
128130
ArLiveEngine.release()
129131
finish()
130132
}
@@ -191,17 +193,12 @@ class PushActivity : BaseActivity() {
191193
}
192194
}
193195

194-
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
195-
if (keyCode == KeyEvent.KEYCODE_BACK){
196-
if (pushType==2){
197-
ScreenShareKit.stop()
198-
}
199-
pusher.stopPush()
200-
ArLiveEngine.release()
201-
finish()
202-
return true
196+
override fun onBackPressed() {
197+
if (pushType==2){
198+
ScreenShareKit.stop()
203199
}
204-
return super.onKeyDown(keyCode, event)
200+
ArLiveEngine.release()
201+
finish()
205202
}
206203

207204

Prj-Android/liveplayer/src/main/cpp/jni/LiveEngine.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,22 @@ Java_io_anyrtc_live_internal_NativeInstance_nativeStopPush(JNIEnv *env, jobject
123123

124124
if (arLivePushKit != NULL&&instance->arLiveEngine!=NULL){
125125
int result =arLivePushKit->stopPush();
126-
instance->arLiveEngine->releaseArLivePusher(arLivePushKit);
127126
return (jint)result;
128127
}
129128
return (jint)-1;
130129
}
131130

131+
JNIEXPORT void JNICALL
132+
Java_io_anyrtc_live_internal_NativeInstance_nativeReleasePusher(JNIEnv *env, jobject obj,jlong nativePtr) {
133+
InstanceHolder *instance = getInstanceHolder(env, obj);
134+
IArLivePusher* arLivePushKit = reinterpret_cast<IArLivePusher *>(nativePtr);
135+
if (arLivePushKit != NULL&&instance->arLiveEngine!=NULL){
136+
instance->arLiveEngine->releaseArLivePusher(arLivePushKit);
137+
}
138+
}
139+
140+
141+
132142

133143
JNIEXPORT jint JNICALL
134144
Java_io_anyrtc_live_internal_NativeInstance_nativeIsPushing(JNIEnv *env, jobject obj,jlong nativePtr) {

Prj-Android/liveplayer/src/main/cpp/jni/liveEngine/AndroidDeviceManager.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ AndroidDeviceManager::~AndroidDeviceManager(void){
3535

3636
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> AndroidDeviceManager::createVideoSource(){
3737
JNIEnv *env = webrtc::AttachCurrentThreadIfNeeded();
38+
if (videoSource){
39+
return videoSource;
40+
}
3841
videoSource = webrtc::CreateJavaVideoSource(env, arlive::StaticThreads::getThreads()->getMediaThread(), false,
3942
false);
4043
return webrtc::VideoTrackSourceProxy::Create(arlive::StaticThreads::getThreads()->getMediaThread(), arlive::StaticThreads::getThreads()->getWorkerThread(),
@@ -196,8 +199,6 @@ void AndroidDeviceManager::destoryCapture(){
196199
if (_capturer!=nullptr){
197200
_capturer.reset();
198201
_capturer = nullptr;
199-
_platformContext.reset();
200-
_platformContext= nullptr;
201202
}
202203
}
203204
int AndroidDeviceManager::setBeautyEffect(bool enable){

Prj-Android/liveplayer/src/main/java/io/anyrtc/live/ArLivePlayer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public abstract class ArLivePlayer {
6767
*/
6868
public abstract int startPlay(String url);
6969

70+
public abstract void releasePlayer();
71+
7072
/**
7173
* 停止播放音视频流。
7274
* @return 返回值 {@link ArLiveCode}

Prj-Android/liveplayer/src/main/java/io/anyrtc/live/ArLivePusher.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ public abstract class ArLivePusher{
181181
*/
182182
public abstract int stopPush();
183183

184+
185+
/**
186+
* 释放推流器
187+
*/
188+
public abstract void releasePusher();
189+
190+
191+
184192
/**
185193
* 当前推流器是否正在推流中。
186194
* @return 是否正在推流

Prj-Android/liveplayer/src/main/java/io/anyrtc/live/internal/ArLiveEngineImpl.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,11 @@ public class ArLiveEngineImpl extends ArLiveEngine {
3737
protected List<ArLivePusherImpl> pusherList = new ArrayList<>();
3838
private ProcessLifecycleOwner mProcessLifecycleOwner = null;
3939

40-
private ArLivePusherImpl pusher;
4140
protected ArDeviceManagerImpl deviceManager;
4241
public ArLiveEngineImpl(Context context) {
4342
this.context = context;
4443
ContextUtils.initialize(context);
4544
applicationHandler = new Handler(context.getMainLooper());
46-
WebRtcAudioManager.setBlacklistDeviceForOpenSLESUsage(true);
4745
nativeInstance = new NativeInstance();
4846
deviceManager = new ArDeviceManagerImpl(nativeInstance,context);
4947
try{
@@ -56,28 +54,25 @@ public ArLiveEngineImpl(Context context) {
5654

5755
}
5856

59-
public ArLivePusherImpl getPusher() {
60-
return pusher;
57+
public List<ArLivePusherImpl> getPusher() {
58+
return pusherList;
6159
}
6260

6361
@Override
6462
public ArLivePusher createArLivePusher() {
65-
if (pusher == null) {
66-
pusher = new ArLivePusherImpl();
67-
pusher.setHandler(applicationHandler,context);
68-
boolean isSuccess = pusher.attach(nativeInstance);
69-
if (isSuccess){
70-
return pusher;
71-
}else {
72-
throw new RuntimeException("not allowed create the ArLivePushKit!");
73-
}
74-
}else {
63+
ArLivePusherImpl pusher = new ArLivePusherImpl();
64+
pusher.setHandler(applicationHandler,context);
65+
boolean isSuccess = pusher.attach(nativeInstance);
66+
if (isSuccess){
67+
pusherList.add(pusher);
7568
return pusher;
69+
}else {
70+
throw new RuntimeException("not allowed create the ArLivePushKit!");
7671
}
77-
7872
}
7973

8074

75+
8176
@Override
8277
public ArLivePlayer createArLivePlayer() {
8378
ArLivePlayerImpl arLivePlayKit = new ArLivePlayerImpl();
@@ -87,7 +82,7 @@ public ArLivePlayer createArLivePlayer() {
8782
playerList.add(arLivePlayKit);
8883
return arLivePlayKit;
8984
}else {
90-
throw new RuntimeException("not allowed create the ArLivePushKit!");
85+
throw new RuntimeException("not allowed create the ArLivePlayerKit!");
9186
}
9287
}
9388

@@ -97,15 +92,18 @@ public void doDestory() {
9792
for (ArLivePlayerImpl arLivePlayer:playerList){
9893
if (arLivePlayer.isNativeOk()){
9994
arLivePlayer.stopPlay();
95+
arLivePlayer.releasePlayer();
10096
}
10197
}
102-
if (pusher!=null){
103-
if (pusher.isNativeOk()){
104-
pusher.stopPush();
98+
for (ArLivePusherImpl arLivePusher:pusherList){
99+
if (arLivePusher.isNativeOk()){
100+
arLivePusher.stopPush();
101+
arLivePusher.releasePusher();
105102
}
106103
}
107104
deviceManager.release();
108105
playerList.clear();
106+
pusherList.clear();
109107
try {
110108
if (this.mProcessLifecycleOwner != null) {
111109
Application app = (Application)context.getApplicationContext();

Prj-Android/liveplayer/src/main/java/io/anyrtc/live/internal/ArLivePlayerImpl.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,13 @@ public int startPlay(String var1) {
101101
}
102102

103103
@Override
104-
public int stopPlay() {
104+
public void releasePlayer() {
105105
detach();
106-
return 0;
106+
}
107+
108+
@Override
109+
public int stopPlay() {
110+
return nativeInstance.nativeStopPlay(nativeId);
107111
}
108112

109113
@Override
@@ -208,9 +212,8 @@ boolean attach(NativeInstance nativeInstance){
208212

209213
void detach(){
210214
synchronized (mPlayerLock){
211-
nativeId = 0;
212-
nativeInstance.nativeStopPlay(nativeId);
213215
nativeInstance.nativePlayKitRelease(nativeId);
216+
nativeId = 0;
214217
isStartPlay = false;
215218
if (renderView!=null){
216219
if (renderView instanceof TextureViewRenderer){

Prj-Android/liveplayer/src/main/java/io/anyrtc/live/internal/ArLivePusherImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,12 @@ public int startPush(String pushUrl) {
390390

391391
@Override
392392
public int stopPush() {
393+
return nativeInstance.nativeStopPush(nativeId);
394+
}
395+
396+
@Override
397+
public void releasePusher() {
393398
detach();
394-
return 0;
395399
}
396400

397401

@@ -487,7 +491,7 @@ boolean attach(NativeInstance nativeInstance){
487491
}
488492

489493
void detach(){
490-
nativeInstance.nativeStopPush(nativeId);
494+
nativeInstance.nativeReleasePusher(nativeId);
491495
nativeId = 0;
492496
if (renderView!=null){
493497
if (renderView instanceof TextureViewRenderer){

0 commit comments

Comments
 (0)