Android custom View for displaying MJPEG stream.
Basic usage
This library is hosted on Maven Central, so make sure you added mavenCentral()
as one of repositories
dependencyResolutionManagement {
...
repositories {
...
mavenCentral()
}
}
Include a library in to your project by adding this to app level build.gradle file.
dependencies {
...
implementation 'com.perthcpe23.dev:android-mjpeg-view:1.1.2'
}
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://app.punyapat.me/mjpeg-server/mjpeg");
viewer.startStream();
//when user leaves application viewer.stopStream();
5. Or Android Compose (skip #3 and #4)
```kotlin
MyApplicationTheme {
Surface(
modifier = Modifier.fillMaxSize(),
) {
AndroidView(
modifier = Modifier.fillMaxSize(),
factory = { context ->
MjpegView(context).apply {
mode = MjpegView.MODE_FIT_WIDTH
isAdjustHeight = true
supportPinchZoomAndPan = true
setUrl("https://app.punyapat.me/mjpeg-server/mjpeg")
startStream()
}
},
)
}
}
<uses-permission android:name="android.permission.INTERNET" />
perth.s28@gmail.com