Android Question CCTV Client MJPEG Class Not Working with string variable

Juan Marrero

Active Member
Licensed User
Hi. I tried using MJPEG Class in B4A (copied from B4J example and modified to B4A) with a string written directly
B4X:
    mj1.Connect("192.168.0.5/", 51042)
and it's working. But if I store that same string in a variable
B4X:
    Dim ip as String = "192.168.0.5/"
mj1.Connect(ip, 51042)
Is not working. It just displays a blank screen, no error.
Any help is appreciated.
mj1 is defined in process_globals as MJPEG
and this is the Frame Sub
B4X:
    Sub mj1_Frame(bmp as Bitmap)
    ImageView1.Bitmap = bmp
End Sub
 

Erel

Administrator
Staff member
Licensed User
It doesn't matter where the string comes from. I can only guess that in the second case there was an extra space or something similar.
 

Juan Marrero

Active Member
Licensed User
I used inputdialog for it from Dialogs Library. When input is returned I compared it like this for testing purposes:
B4X:
    Dim ip as String = "192.168.0.5/"

If ip = "192.168.0.5/" Then
    mj1.Connect("192.168.0.5/", 51042)
End If
And it entered the If Statement.

B4X:
Dim input As InputDialog
  
input.InputType = input.INPUT_TYPE_TEXT
Dim ans As Int = input.Show("Enter Server IP:", "IP", "OK", "", "Cancel", Null)
Dim ip As String
 
If ans = DialogResponse.POSITIVE Then
    ip = input.Input
End If

If ip = "192.168.0.5/" Then
    mj1.Connect("192.168.0.5/", 51042)
End If
 

Erel

Administrator
Staff member
Licensed User
As I said, it doesn't matter where the string comes from.
 

Juan Marrero

Active Member
Licensed User
Ok. For some reason is not working for me. I'll have to dig more. Thanks. I solved it using a hotspot and I know that Android's default IP is 192.168.43.1 I used it directly in code.
 

jimmyF

Active Member
Licensed User
Try dropping the '/' from the end of the IP address.
The app concatenates the ip and the port so you may end up with this:

192.168.0.5/:51042 which is incorrect.

Just a thought.

-j
 

Juan Marrero

Active Member
Licensed User
Dropping the '/' gives me the following error: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
 
Top