TakuSemba / RtmpPublisher

Rtmp client on Android. Live Video Streaming.
Apache License 2.0
628 stars 149 forks source link

Sometimes can not publish #33

Open Anveena opened 4 years ago

Anveena commented 4 years ago

in Streamer class: startStreaming method: if (muxer.isConnected()) this condition called after muxer.open(url, width, height); but muxer.open is async method. so sometimes run muxer.isConnected() then run rtmpMuxer.open((String) msg.obj, msg.arg1, msg.arg2); that's make muxer.isConnected() allways return false; so in Muxer class: private ArrayBlockingQueue waiterLock = new ArrayBlockingQueue<>(10); void open(String url, int width, int height) { Message message = handler.obtainMessage(MSG_OPEN, url); message.arg1 = width; message.arg2 = height; handler.sendMessage(message); try { waiterLock.take(); } catch (InterruptedException e) { e.printStackTrace(); } }

case MSG_OPEN: rtmpMuxer.open((String) msg.obj, msg.arg1, msg.arg2); try { if (listener != null) { uiHandler.post(new Runnable() { @Override public void run() { if (isConnected()) { listener.onStarted(); disconnected = false; closed = false; } else { listener.onFailedToConnect(); } } }); } waiterLock.put(true); } catch (InterruptedException e) { e.printStackTrace(); break; } break;