use of com.red5pro.streaming.event.R5ConnectionEvent in project streaming-android by red5pro.
the class TwoWayTest method onSubscribeReady.
private void onSubscribeReady() {
if (subscribe != null)
return;
System.out.println("bitrate - subscribe start");
Handler r = new Handler(Looper.getMainLooper());
final R5ConnectionListener additionalListener = this;
r.post(new Runnable() {
@Override
public void run() {
System.out.println("Subscribing");
R5Configuration config = new R5Configuration(R5StreamProtocol.RTSP, TestContent.GetPropertyString("host"), TestContent.GetPropertyInt("port"), TestContent.GetPropertyString("context"), TestContent.GetPropertyFloat("subscribe_buffer_time"));
config.setLicenseKey(TestContent.GetPropertyString("license_key"));
config.setBundleID(getActivity().getPackageName());
R5Connection connection = new R5Connection(config);
// setup a new stream using the connection
subscribe = new R5Stream(connection);
// show all logging
subscribe.setLogLevel(R5Stream.LOG_LEVEL_DEBUG);
// find the view and attach the stream
display.attachStream(subscribe);
display.showDebugView(TestContent.GetPropertyBool("debug_view"));
R5ConnectionListener listener = new R5ConnectionListener() {
@Override
public void onConnectionEvent(R5ConnectionEvent r5ConnectionEvent) {
// additionalListener.onConnectionEvent(r5ConnectionEvent);
Log.d("Subscriber", ":onConnectionEvent " + r5ConnectionEvent.name());
if (r5ConnectionEvent == R5ConnectionEvent.START_STREAMING) {
isSubscribing = true;
}
if (r5ConnectionEvent == R5ConnectionEvent.ERROR) {
subscribe.stop();
subscribe = null;
isSubscribing = false;
sendRemoteCall();
}
if (r5ConnectionEvent == R5ConnectionEvent.DISCONNECTED) {
if (isSubscribing) {
isSubscribing = false;
subscribe.stop();
subscribe = null;
}
}
}
};
subscribe.setListener(listener);
// Unlike basic subscription, two-way needs echo cancellation, which needs the subscriber and publisher
// to use the same Audio Controller - instead of recreating it for stability, we delay the subscriber
subscribe.play(TestContent.GetPropertyString("stream2"));
killListThread();
}
});
}
use of com.red5pro.streaming.event.R5ConnectionEvent in project streaming-android by red5pro.
the class TwoWayTest method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.twoway_test, container, false);
preview = (R5VideoView) rootView.findViewById(R.id.videoPreview);
publish();
publish.client = this;
final R5ConnectionListener additionalListener = this;
publish.setListener(new R5ConnectionListener() {
@Override
public void onConnectionEvent(R5ConnectionEvent r5ConnectionEvent) {
additionalListener.onConnectionEvent(r5ConnectionEvent);
if (r5ConnectionEvent == R5ConnectionEvent.START_STREAMING) {
isPublishing = true;
sendRemoteCall();
}
if (r5ConnectionEvent == R5ConnectionEvent.DISCONNECTED) {
if (isSubscribing) {
isSubscribing = false;
subscribe.stop();
subscribe = null;
}
isPublishing = false;
}
}
});
display = (R5VideoView) rootView.findViewById(R.id.videoView);
return rootView;
}
use of com.red5pro.streaming.event.R5ConnectionEvent in project streaming-android by red5pro.
the class SubscribeReconnectTest method SetupListener.
public void SetupListener() {
final R5ConnectionListener additionalListener = this;
final SubscribeReconnectTest subscribeTest = this;
final R5Stream subscriber = this.subscribe;
final R5VideoView view = this.display;
subscribe.setListener(new R5ConnectionListener() {
@Override
public void onConnectionEvent(R5ConnectionEvent r5ConnectionEvent) {
final R5ConnectionListener me = this;
additionalListener.onConnectionEvent(r5ConnectionEvent);
if (r5ConnectionEvent == R5ConnectionEvent.CLOSE && !SubscribeReconnectTest.this.stopped) {
Handler h = new Handler(Looper.getMainLooper());
h.postDelayed(new Runnable() {
@Override
public void run() {
if (!stopped) {
subscribeTest.findStreams();
}
}
}, reconnectDelay);
} else if (r5ConnectionEvent == R5ConnectionEvent.NET_STATUS && r5ConnectionEvent.message.equals("NetStream.Play.UnpublishNotify")) {
Handler h = new Handler(Looper.getMainLooper());
h.postDelayed(new Runnable() {
@Override
public void run() {
subscriber.setListener(null);
subscriber.stop();
view.attachStream(null);
subscribeTest.delayReconnect(reconnectDelay);
}
}, reconnectDelay);
}
}
});
}
Aggregations