How do you close a video stream from Android?

Hello, I’m using the SDK for Android and I’m having trouble closing a video stream before exiting that activity. I looked the samples, read the docs and no clue whatsoever…

Currently I have tried this methods:

  • xpMobileSDK.stopVideoStream: this method effectively stops the video, but from what I have seend, a background thread throws some errors because it is expecting the video frames. The error I usually get is this:
D/VideoChannelThread: Exception in vStream.receiveResponse()
    java.net.SocketTimeoutException: failed to connect to /10.51.70.2 (port 8081) after 10000ms
        at libcore.io.IoBridge.connectErrno(IoBridge.java:169)
        at libcore.io.IoBridge.connect(IoBridge.java:122)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
        at java.net.Socket.connect(Socket.java:882)
        at com.android.okhttp.internal.Platform.connectSocket(Platform.java:174)
        at com.android.okhttp.Connection.connect(Connection.java:1222)
        at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:395)
        at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:298)
        at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:399)
        at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:349)
        at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseMessage(HttpURLConnectionImpl.java:513)
        at com.milestonesys.xpmobilesdk.communication.HTTPConnection.getResponseInputStream(HTTPConnection.java:284)
        at com.milestonesys.xpmobilesdk.communication.HTTPConnection.receiveResponse(HTTPConnection.java:273)
        at com.milestonesys.xpmobilesdk.communication.VideoChannelThread.pullVideo(VideoChannelThread.java:398)
        at com.milestonesys.xpmobilesdk.communication.VideoChannelThread.access$1200(VideoChannelThread.java:25)
        at com.milestonesys.xpmobilesdk.communication.VideoChannelThread$1.run(VideoChannelThread.java:241)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:818)
    Thread for VideoStream 'b8af71d4-406c-4cb5-9adb-85c5feab9fc1' will be closed.
    Thread for VideoStream 'b8af71d4-406c-4cb5-9adb-85c5feab9fc1' has been closed!
W/System.err: java.util.concurrent.CancellationException
        at java.util.concurrent.FutureTask.report(FutureTask.java:92)
        at java.util.concurrent.FutureTask.get(FutureTask.java:163)
        at com.milestonesys.xpmobilesdk.communication.VideoChannelThread.run(VideoChannelThread.java:280)

Also sometimes this error occurs:

E/HTTPConnection: Exception while sending request!: 
    java.net.SocketTimeoutException: failed to connect to /10.51.70.2 (port 8081) after 10000ms

Sometimes I even get some infinite errors like this one:

Exception while reading video stream!
    java.io.IOException: unexpected end of stream
        at com.android.okhttp.internal.http.HttpConnection$ChunkedSource.read(HttpConnection.java:525)
        at com.android.okio.RealBufferedSource$1.read(RealBufferedSource.java:174)
        at com.milestonesys.xpmobilesdk.communication.VideoChannelThread$1.run(VideoChannelThread.java:127)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:818)

(Please note this three errors occur from executing the stopVideoSteam method, just that sometimes is one, sometimes is other)

  • xpMobileSDK.cancelRequest (doesn’t do anything to me, doesn’t even get to the callback)

Please, I would appreciate your help.

Hello,

Using StopVideoStream is indeed the correct way, as it will send the CloseStream command to the mobile server (which will in turn close the video connection from the server side and free the associated resources).

However, if you are using the VideoFactory convenience class, its internal video receiver thread doesn’t know the stream has been closed and will try to continue reading from it - which will throw an exception (the exception will be different depending on the exact moment the stream happens to be closed).

I don’t know what to recommend here. You could either live with the exception (eventually the thread closes), or do not use LiveVideo/VideoFactory and handle the job of receiving video yourself. This requires a lot more work.

We should consider adding a clean way to stop video from the VideoFactory in one of the next MobileSDK releases, but this will not fix your immediate problem…

Hello,

I guess I’ll keep it like this until we can stop it from the VideoFactory then.

Appreciate your answer, thanks!