Search in sources :

Example 1 with R5ConnectionListener

use of com.red5pro.streaming.event.R5ConnectionListener in project streaming-android by red5pro.

the class SubscribeTwoStreamTest method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.double_view, container, false);
    // Create the configuration from the tests.xml
    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);
    subscribe.setListener(this);
    subscribe.audioController = new R5AudioController();
    subscribe.audioController.sampleRate = TestContent.GetPropertyInt("sample_rate");
    // show all logging
    subscribe.setLogLevel(R5Stream.LOG_LEVEL_DEBUG);
    // find the view and attach the stream
    display = (R5VideoView) view.findViewById(R.id.videoView1);
    display.attachStream(subscribe);
    display.showDebugView(TestContent.GetPropertyString("debug_view").equals("true"));
    subscribe.play(TestContent.GetPropertyString("stream1"));
    secondDisplay = (R5VideoView) view.findViewById(R.id.videoView2);
    final R5ConnectionListener listener = this;
    final Handler root = new Handler(Looper.getMainLooper());
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Thread.sleep(4000);
                Looper.prepare();
                root.post(new Runnable() {

                    @Override
                    public void run() {
                        R5Configuration config2 = new R5Configuration(R5StreamProtocol.RTSP, TestContent.GetPropertyString("host"), TestContent.GetPropertyInt("port"), TestContent.GetPropertyString("context"), TestContent.GetPropertyFloat("subscribe_buffer_time"));
                        config2.setLicenseKey(TestContent.GetPropertyString("license_key"));
                        config2.setBundleID(getActivity().getPackageName());
                        R5Connection secondConnection = new R5Connection(config2);
                        secondSubscribe = new R5Stream(secondConnection);
                        secondSubscribe.setListener(listener);
                        secondDisplay.attachStream(secondSubscribe);
                        secondDisplay.showDebugView(TestContent.GetPropertyString("debug_view").equals("true"));
                        secondSubscribe.audioController = new R5AudioController();
                        secondSubscribe.audioController.sampleRate = TestContent.GetPropertyInt("sample_rate");
                        secondSubscribe.play(TestContent.GetPropertyString("stream2"));
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();
    return view;
}
Also used : R5ConnectionListener(com.red5pro.streaming.event.R5ConnectionListener) R5Configuration(com.red5pro.streaming.config.R5Configuration) R5Connection(com.red5pro.streaming.R5Connection) R5Stream(com.red5pro.streaming.R5Stream) Handler(android.os.Handler) R5AudioController(com.red5pro.streaming.media.R5AudioController) R5VideoView(com.red5pro.streaming.view.R5VideoView) View(android.view.View)

Example 2 with R5ConnectionListener

use of com.red5pro.streaming.event.R5ConnectionListener 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();
        }
    });
}
Also used : R5ConnectionListener(com.red5pro.streaming.event.R5ConnectionListener) R5Configuration(com.red5pro.streaming.config.R5Configuration) R5Connection(com.red5pro.streaming.R5Connection) R5Stream(com.red5pro.streaming.R5Stream) Handler(android.os.Handler) R5ConnectionEvent(com.red5pro.streaming.event.R5ConnectionEvent)

Example 3 with R5ConnectionListener

use of com.red5pro.streaming.event.R5ConnectionListener 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;
}
Also used : R5ConnectionListener(com.red5pro.streaming.event.R5ConnectionListener) R5ConnectionEvent(com.red5pro.streaming.event.R5ConnectionEvent) R5VideoView(com.red5pro.streaming.view.R5VideoView) View(android.view.View)

Example 4 with R5ConnectionListener

use of com.red5pro.streaming.event.R5ConnectionListener 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);
            }
        }
    });
}
Also used : R5ConnectionListener(com.red5pro.streaming.event.R5ConnectionListener) R5VideoView(com.red5pro.streaming.view.R5VideoView) R5Stream(com.red5pro.streaming.R5Stream) R5ConnectionEvent(com.red5pro.streaming.event.R5ConnectionEvent) Handler(android.os.Handler)

Aggregations

R5ConnectionListener (com.red5pro.streaming.event.R5ConnectionListener)4 Handler (android.os.Handler)3 R5Stream (com.red5pro.streaming.R5Stream)3 R5ConnectionEvent (com.red5pro.streaming.event.R5ConnectionEvent)3 R5VideoView (com.red5pro.streaming.view.R5VideoView)3 View (android.view.View)2 R5Connection (com.red5pro.streaming.R5Connection)2 R5Configuration (com.red5pro.streaming.config.R5Configuration)2 R5AudioController (com.red5pro.streaming.media.R5AudioController)1