Onvif (stands for: O pen N etwork V ideo I nterface F orum) is a non-profit with the goal of facilitating the development and use of a global open standard for the interface of physical IP-based security products — Wikipedia Being able to control your house, open doors, view in real time your living room, control the lights is a childhood dream! I was really delighted to develop an app and a dependency to ease the development of ONVIF Android apps. ONVIF goal is to standardise how IP products (video surveillance cameras, alarms, doors, audio recorders…) communicate with each others. They created some specifications manufacturers have to conform to to be compliant with ONVIF. The goal behind these specifications is to standardise how to connect to these products, for instance if you develop an app for streaming video from an ONVIF camera, it should work with every ONVIF camera. Try it! If you just want to try the demo project, you can download the . Open it with Android Studio and run it, that’s it! sample project on Github You will be able to login on ONVIF camera and view its live stream: every Streaming from an ONVIF cameraHow to connect to a camera and visualise its live stream on Android? 👨🏽💻 Create a new project on Android Studio Add implementation and implementation to your (Module: app) com.rvirin.onvif:onvifcamera:1.1.6 com.squareup.okhttp3:okhttp:3.10.0 build.gradle Once it’s done, you can add the following code to connect to the camera and retrieve its information: (), OnvifListener { { .onCreate(savedInstanceState) setContentView(R.layout.activity_main) currentDevice = OnvifDevice( , , ) currentDevice.listener = currentDevice.getServices() } { Log.d( , ) Log.d( , : class MainActivity AppCompatActivity override fun onCreate (savedInstanceState: ?) Bundle super "IP_ADDRESS:PORT" "login" "pwd" this override fun requestPerformed (response: ) OnvifResponse "ONVIF" "Request performed." ${response.request.type} "ONVIF" "Succeeded: , message: ”) if (response.request.type == GetServices) { currentDevice.getDeviceInformation() } } } ${response.success} ${response.parsingUIMessage} To instantiate an ONVIF camera, we use the class , this class takes an which defines the method. This method is called once the camera returns a call we made (getDeviceInformation, getProfiles, getStreamUri). OnvifDevice OnvifListener requestPerformed() Calling before getting the information is not mandatory but strongly recommended. It retrieves the different paths depending on the web service you’re calling, from one camera to another it can change. For instance command will have this path on a Dahua camera whereas it will be on a Uniview camera. Note: getServices getProfiles /onvif/media2_service /onvif/media2 If you implement new web services call in your app, you need to parse their path in this call. To be able to see the live stream of the camera we need to retrieve the different profiles (media profiles, with different configurations available) from the camera, select the one we want to play and retrieve the corresponding stream URI. Here is how we retrieve the profiles and the stream URI: { Log.d( , ) Log.d( , ONVIF Stream URI retrieved: ${currentDevice.rtspURI} override fun requestPerformed (response: ) OnvifResponse "ONVIF" "Request performed." ${response.request.type} "ONVIF" "Succeeded: , message: ”) if (response.request.type == GetServices) { currentDevice.getDeviceInformation() } else if (response.request.type == GetDeviceInformation) { currentDevice.getProfiles() } else if (response.request.type == GetProfiles) { currentDevice.getStreamURI() } else if (response.request.type == GetStreamURI) { Log.d(" ${response.success} ${response.parsingUIMessage} ", " ") } } } Depending on your camera, your URI will look like this one: etc… rtsp://IP_ADDRESS:PORT/cam/realmonitor?channel=1 The URI does not follow the http protocol, but the rtsp protocol, which is normal because (Real Time Streaming Protocol) is aiming to make streaming simpler. The problem is, doesn’t handle RTSP well (it can work but not with every codec, which is a problem to stream from an ONVIF camera). Fortunately, comes to the rescue! RTSP VideoView VLC How to read a RTSP stream on Android? 🎥 Add these lines to your build.gradle: { { maven { url } } } { } allprojects repositories 'https://jitpack.io' dependencies compile 'com.github.pedroSG94.vlc-example-streamplayer:pedrovlc:2.5.14' Here is how you play the video with once you have the rtsp URI: libVLC (), VlcListener { vlcVideoLibrary: VlcVideoLibrary? = { .onCreate(savedInstanceState) setContentView(R.layout.activity_stream) surfaceView = findViewById<SurfaceView>(R.id.surfaceView) vlcVideoLibrary = VlcVideoLibrary( , , surfaceView) vlcVideoLibrary?.play(url) } { Toast.makeText( , , Toast.LENGTH_SHORT).show() } { Toast.makeText( , , Toast.LENGTH_SHORT).show() vlcVideoLibrary?.stop() } } : class StreamActivity AppCompatActivity private var null override fun onCreate (savedInstanceState: ?) Bundle super val this this override fun onComplete () this "Playing" override fun onError () this "Error, make sure your endpoint is correct" implements two methods ( , and ). They are called by to tell us if the video loads without any problem. VLCListener onComplete() onError() VlcVideoLibrary You can also insert the login and password in the rtsp uri like this: etc… If you use the dependency, the URI saved in contains the login and password. Tip: rtsp:// login:password @IP_ADDRESS:PORT/cam/realmonitor?channel=1 ONVIFCamera OnvifDevice.rtspUri If you want to learn how to create the same project on , you can read . iOS this article Creating an ONVIF library was a exciting opportunity, as you can see in my , I really enjoy having an interaction between my apps and hardware devices, whether it’s a printer for iPhone, a camera, or even a door! I’m really looking forward to test new ONVIF devices and develop apps that can be useful for everyone that has ONVIF devices. previous posts The code of this project is open source, you can download it on . Github If you have any question, I’ll be happy to read them in the comments!