Good morning,
can somebody show me how to get this VB code working in B4J, the attached version does block the main thread and can't seek in the file if necessary.
THX
can somebody show me how to get this VB code working in B4J, the attached version does block the main thread and can't seek in the file if necessary.
THX
B4X:
'VB code
Dim fi As New IO.FileInfo(StreamLocation)
Dim fs As New IO.FileStream(StreamLocation, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read, 188, IO.FileOptions.SequentialScan)
fs.Position = 0
While bwReader.CancellationPending = False And EndOfStream = False
VolumeRead = fs.Read(buffer, 0, 188)
If VolumeRead <> 188 Then
' End of file
EndOfStream = True
Else
' Test if sync byte isn't present at the beginning => problem
If buffer(0) <> &H47 Then
Input_BadLength += 1
' Searching the next sync byte
SyncFound = 200
For i = 1 To 187
If buffer(i) = &H47 Then
If i < SyncFound Then SyncFound = i
End If
Next
' If sync found, we resync the stream reading, if not, we wait for the next packet
If SyncFound < 200 Then
fs.Position = fs.Position - 188 + SyncFound
End If
Else
' Packet OK
Input_TSPacketsReceived += 1
Analyzer.NewPacket(buffer)
End If
End If
End While
fs.Close()
B4X:
'B4J code
Dim in As InputStream = File.OpenInput(filepath, filename)
Log( "Start: " & DateTime.Time(now))
DoWhile VolumeRead <> - 1' Or EndOfStream = True
VolumeRead = in.ReadBytes( buffer, 0, buffer.Length)
If VolumeRead <> 188 Then
' End of File
EndOfStream = True
Else
' test If sync byte isn't present at the beginning => problem
If buffer(0) <> 0x47 Then
Input_BadLength = Input_BadLength + 1
' Searching the Next sync byte
SyncFound = 200
For i = 1 To 186
If buffer(i) = 0x47 Then
If i < SyncFound Then SyncFound = i
End If
Next
' If sync found, we resync the stream reading, If Not, we wait For the Next packet
If SyncFound < 200 Then
' fs.Position = fs.Position - 188 + SyncFound 'howto seek in the file with B4J ?
i = i
End If
Else
' Packet OK
Input_TSPacketsReceived = Input_TSPacketsReceived + 1
NewPacket(buffer)
EndIf
EndIf
Loop