Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error on back button/pause android.os.NetworkOnMainThreadException #86

Open
yeahman45 opened this issue Dec 15, 2019 · 2 comments

Comments

@yeahman45
Copy link

I am using the same code as the sample app :
https://github.com/niqdev/ipcam-view/blob/master/app/src/main/java/com/github/niqdev/ipcam/IpCamDefaultActivity.java

i.e. stopPlayback onPause

But when it pauses/back button, I get the following fatal exception:

2019-12-15 22:17:14.573 29392-29392/com.myapp.app E/MessageQueue-JNI: android.os.NetworkOnMainThreadException at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1448) at com.android.org.conscrypt.Platform.blockGuardOnNetwork(Platform.java:325) at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:724) at com.android.okhttp.okio.Okio$2.read(Okio.java:142) at com.android.okhttp.okio.AsyncTimeout$2.read(AsyncTimeout.java:218) at com.android.okhttp.okio.RealBufferedSource.read(RealBufferedSource.java:56) at com.android.okhttp.internal.http.Http1xStream$ChunkedSource.read(Http1xStream.java:886) at com.android.okhttp.internal.Util.skipAll(Util.java:159) at com.android.okhttp.internal.Util.discard(Util.java:141) at com.android.okhttp.internal.http.Http1xStream$ChunkedSource.close(Http1xStream.java:919) at com.android.okhttp.okio.RealBufferedSource.close(RealBufferedSource.java:402) at com.android.okhttp.okio.RealBufferedSource$1.close(RealBufferedSource.java:390) at java.io.BufferedInputStream.close(BufferedInputStream.java:485) at java.io.FilterInputStream.close(FilterInputStream.java:181) at com.github.niqdev.mjpeg.MjpegViewDefault._stopPlayback(MjpegViewDefault.java:276) at com.github.niqdev.mjpeg.MjpegViewDefault.stopPlayback(MjpegViewDefault.java:417) at com.github.niqdev.mjpeg.MjpegSurfaceView.stopPlayback(MjpegSurfaceView.java:134) at com.myapp.app.fragments.CameraViewFragment.onPause(CameraViewFragment.java:108)

I don't know if this causes the following problem:
When I view a mjpeg stream and I go back. I re-view the mjpeg stream, the fps drops. The more I go back and re-view the mjpeg stream, the more the fps drops until it becomes unwatchable.

@yeahman45
Copy link
Author

I think I found the solution.
I run the mjpegView.stopPlayback() in a thread. There is no more the fatal exception and there's no more the FPS drop issue.

@witti-stephen
Copy link

Following your idea, I apply the code as follow and the issue is gone:

override fun onPause() {
    super.onPause()
    GlobalScope.launch(Dispatchers.IO) {
        binding.mjpegView.stopPlayback()
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants