Hi
Seems you are trying to get an impossible equality. You are comparing a 64 byte sequence with a 4 (or 6 whatever) sequence which can never be equal.
I added a Function that pairs down the 64 bytes for a comparison. I have only tested with one of the file types and works fine so maybe it would work fine for all.
' Form1 with Lavel1
Option Strict On
Option Explicit On
Imports System.IO
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Label1.Text = DetectMagicNo("C:\Users\lesha\Desktop\sample-ogg.ogg")
End Sub
Public Function DetectMagicNo(InputFile As String) As String
Using MyFileStream As New FileStream(InputFile, FileMode.Open, FileAccess.Read)
Dim MyBytes(63) As Byte
Dim OGG As Byte() = {&H4F, &H67, &H67, &H53}
Dim PSD As Byte() = {&H38, &H42, &H50, &H53}
Dim MP3 As Byte() = {&HFF, &HFB, &HFF, &HF3, &HFF, &HF2}
MyFileStream.Read(MyBytes, 0, 64)
Select Case True
Case Tk(4, MyBytes).SequenceEqual(OGG)
Return "OGG"
Case Tk(4, MyBytes).SequenceEqual(PSD)
Return "PSD"
Case Tk(6, MyBytes).SequenceEqual(MP3)
Return "MP3"
End Select
End Using
Return "None"
End Function
Function Tk(n As Integer, bytes() As Byte) As Byte()
Dim b(n - 1) As Byte
For i As Integer = 0 To n - 1
b(i) = bytes(i)
Next
Return b
End Function
End Class