Android View for displaying MJPEG stream.
- This view only requires a specific http url.
- Supported image scaling methods are fit width, fit height, original size, stretch and best fit.
- Only boundary is used to separate each jpeg image (each frame) from a stream. Content-length is ignored.
- A boundary must be specified in an HTTP headr (Content-type). Otherwise a default boundary pattern will be used.
Basic usage
- This library is hosted on JitPack, so add it in your root build.gradle at the end of repositories.
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Include a library in to your project by adding this to app level build.gradle file.
dependencies {
// other dependencies
implementation 'com.github.perthcpe23:android-mjpeg-view:v1.0.9'
}
- Add a view to XML layout:
<com.longdo.mjpegviewer.MjpegView
android:id="@+id/mjpegview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
- Specify mjpeg source and start streaming
MjpegView viewer = (MjpegView) findViewById(R.id.mjpegview);
viewer.setMode(MjpegView.MODE_FIT_WIDTH);
viewer.setAdjustHeight(true);
viewer.setSupportPinchZoomAndPan(true);
viewer.setUrl("https://bma-itic1.iticfoundation.org/mjpeg2.php?camid=test");
viewer.startStream();
//when user leaves application
viewer.stopStream();
- Don't forget to add internet access permission to Android manifests file
<uses-permission android:name="android.permission.INTERNET" />
- You can also download .aar at https://github.com/perthcpe23/android-mjpeg-view/tree/master/arr