如何在VB.NET中找到mp3的标题 [英] How do I find header of mp3 in VB.NET

查看:71
本文介绍了如何在VB.NET中找到mp3的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法得到结果



在delphi我写这个函数我可以得到它



 function getMP3Header(filename:string; pos:Integer):TMP3HeaderArray; 
var filemp3:文件;
headerArray:TMP3HeaderArray;
count:整数;如果FileExists(文件名)然后
开始
AssignFile(filemp3,filename);
开始

FileMode:= fmOpenRead;
重置(filemp3,1);
seek(filemp3,pos);
BlockRead(filemp3,
headerArray,4,count);
结果:= headerArray;
CloseFile(filemp3);
结束其他
开始
退出;
结束;
结束;





我尝试过:



i在vb.net中使用此函数



 Public mp3headerarray(0 To 3)As Byte 



公共函数GetMp3Header(ByVal filename As String,ByVal pos As Integer)As Byte()
Dim count As Integer
Dim result()As Byte
Dim headerarray = mp3headerarray

如果IO.File.Exists(filename)则
使用Stream作为新FileStream(filename,FileMode.Open,FileAccess。阅读)
Stream.Seek(pos,SeekOrigin.Current)
Stream.Read(headerarray,0,4)
result = headerarray
Stream.Close()
结束使用
结束如果

Catch ex As Exception
MsgBox(ex.Message +get Mp3 Header)
结束尝试

返回结果
结束函数





表示变量结果是u sed在被赋值之前

谢谢

解决方案

你宣布数组为

  Dim  result() As   Byte  

然后数组的值为 Nothing 。但是您的函数返回该变量并且它并不总是设置(仅在文件存在时设置)。另见变量'< variablename>'在被赋值之前使用Microsoft Docs [ ^ ]。



To避免这种情况你可以创建零长度数组 [ ^ ]:

 < span class =code-keyword> Dim  result(-1) As   Byte  


i can't get the result

in delphi i write this function and i can get it

function getMP3Header(filename: string; pos: Integer): TMP3HeaderArray; 
var   filemp3: File;   
headerArray: TMP3HeaderArray;  
 count: integer; 
begin   
if FileExists(filename) then 
  begin    
 AssignFile(filemp3, filename);    
 FileMode:=fmOpenRead;    
 Reset(filemp3,1);     
seek(filemp3, pos);     
BlockRead(filemp3, 
headerArray, 4, count);    
 Result:=headerArray;     
CloseFile(filemp3);   
end else   
begin     
exit;  
end; 
end;



What I have tried:

i use this function in vb.net

Public mp3headerarray(0 To 3) As Byte


 Public Function GetMp3Header(ByVal filename As String, ByVal pos As Integer) As Byte()
Dim count As Integer
Dim result() As Byte
Dim headerarray = mp3headerarray

 If IO.File.Exists(filename) Then
            Using Stream As New FileStream(filename, FileMode.Open, FileAccess.Read)
                Stream.Seek(pos, SeekOrigin.Current)
                Stream.Read(headerarray, 0, 4)
                result = headerarray
                Stream.Close()
            End Using
        End If

         Catch ex As Exception
            MsgBox(ex.Message + "get Mp3 Header")
        End Try

        Return result
    End Function



it's said variable result is used before it has been assigned a value
thanks

解决方案

You are declaring the array as

Dim result() As Byte

Then the array has the value Nothing. But your function returns that variable and it is not always set (it is only set when the file exists). See also Variable '<variablename>' is used before it has been assigned a value | Microsoft Docs[^].

To avoid this you can create a Zero-length array[^]:

Dim result(-1) As Byte


这篇关于如何在VB.NET中找到mp3的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆