Android Question CCTV Client MJPEG Class Not Working with string variable

Juan Marrero

Active Member
Licensed User
Longtime 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
 

Juan Marrero

Active Member
Licensed User
Longtime 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
 
Upvote 0

Juan Marrero

Active Member
Licensed User
Longtime 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.
 
Upvote 0

jimmyF

Active Member
Licensed User
Longtime 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
 
Upvote 0

Juan Marrero

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

jimmyF

Active Member
Licensed User
Longtime User
What jdk are you using?
 
Upvote 0
Top