Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("wMain")
oSFcn.Initialize
oSck.Initialize("oSock")
oSBT.Initialize
'socket.RemoteHost = "plazacam.studentaffairs.duke.edu"
oTmr.Initialize("oTmer", 500)
oTmr.Enabled = True
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub oTmer_Tick
If oSck.Connected = False Then ConnectSocket
End Sub
Sub ConnectSocket
'oSck.Connect("96.249.39.25", 80, 3000)
oSck.Connect("195.113.207.238", 80, 3000)
End Sub
Sub oSock_Connected(Successful As Boolean)
If Successful Then
oAStreams.Initialize(oSck.InputStream, oSck.OutputStream, "oAStreams")
Dim byBuffer() As Byte, sTmp As String
' sTmp = "GET /axis-cgi/mjpg/video.cgi?resolution=640x480&dummy=1480384795175 HTTP/1.1" & _
' Chr(10) & Chr(13) & "Host: 96.249.39.25" & Chr(10) & Chr(13) & _
' "Connection: keep-alive" & Chr(10) & Chr(13) & Chr(10) & Chr(13)
sTmp = "GET /mjpg/video.mjpg HTTP/1.1" & Chr(13) & Chr(10) & "Host: 195.113.207.238" & _
Chr(13) & Chr(10) & "Connection: keep-alive" & Chr(13) & Chr(10) & Chr(13) & Chr(10)
byBuffer = sTmp.GetBytes("UTF8")
oAStreams.Write(byBuffer)
End If
End Sub
Sub oAStreams_NewData (Buffer() As Byte)
oSBT.Append(BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
dd = oSBT.ToString
If ContentLength = 0 Then
i1 = oSFcn.InString(dd, "Content-Length: ")
If i1 > 0 Then ' Remove the MPEG header and get file length
Dim sTp As String
i1 = i1 + 16
sTp = oSFcn.MidS(dd, i1)
i2 = oSFcn.InString(sTp, Chr(13) & Chr(10) & Chr(13) & Chr(10))
If i2 > 0 Then
ContentLength = oSFcn.Mid(dd, i1, i2 + 1)
dd = oSFcn.MidS(dd, i2 + 4)
End If
End If
End If
If ContentLength > 0 AND oSFcn.Len(dd) >= ContentLength Then 'Get JPEG content, convert to image and show
Log(ContentLength)
Log(oSFcn.Len(dd))
ByteArray = dd.GetBytes("UTF8") ' In original code, ByteArray Langht = String lenght
Log(ByteArray.Length) ' Here, ByteArray lenght is almost x2
dd = oSFcn.MidS(dd, ContentLength)
ContentLength = 0
oSBT.Initialize
ivVideo1.Bitmap = BytesToImage(ByteArray)
DoEvents
End If
End Sub
Sub oAStreams_Error
ToastMessageShow(LastException.Message, True)
Log(LastException.Message)
End Sub
Sub oAStreams_Terminated
Log("AStreams_Terminated")
End Sub
Public Sub BytesToImage(bytes() As Byte) As Bitmap
Dim In As InputStream
Log(bytes.Length)
In.InitializeFromBytesArray(bytes, 0, bytes.Length - 1)
Dim bmp As Bitmap
bmp.Initialize2(In) ' <<< Here occurs the error
Return bmp
End Sub