我要从打开多个文件时动态的将MP3  的ID3添到Listview里,但是老是出现Cannot open files 
id3的代码用的是
type 
TID3Tag = packed record // 128 字节
   TAGID: array[0..2] of char; // 3 字节: 必须是TAG
   Title: array[0..29] of char; // 30 字节: 歌曲标题
   Artist: array[0..29] of char; // 30 字节: 歌曲的艺术家
   Album: array[0..29] of char; // 30 字节: 歌曲专辑
   Year: array[0..3] of char; // 4 字节: 出版年
   Comment: array[0..29] of char; // 30 字节: 评论
   Genre: byte; // 1 字节: 种类标识
end; //打开文件部分
pro............. 
var
 _mp3file:string;
  id3tag: Tid3tag;
  mp3file: Tfilestream; 
begin
if OP....THEN
BEGIN
.....
  mp3file:=Tfilestream.create(_mp3file,fmOpenRead);
  try
    mp3file.position:=mp3file.size-128; // 跳到id3-tag
    mp3file.Read(id3tag,SizeOf(id3tag));
    
//开始写入    
  finally
    mp3file.free;
  end; 
end; 
我用TListview.hint(已经添加)刚没有什么问题出现,我想可能是文件还没有初始化。还是怎么的。
不知道怎么来解决这个问题。请大家帮帮忙

解决方案 »

  1.   

    for i:=0 to OpenDialog1.Files.count -1 do
    begin
      _mp3file:=Opendialog1.files[i];
       mp3file:=TFileStream.Create(_mp3file,fmOpenRead);
      ......
    end;
    帮帮UPup做不出来。
      

  2.   

    不知道这段代码对我有不有帮助请大家看看
    type
      TID3Tag = record
        Tag: array[0..2] of Char;
        Songname: array[0..29] of Char;
        Artist: array[0..29] of Char;
        Album: array[0..29] of Char;
        Year: array[0..3] of Char;
        Comment: array[0..29] of Char;
        Genre: Byte;
      end;type
      TID3Info = class(TForm)
        Edit1: TEdit;
        Edit2: TEdit;
        Edit3: TEdit;
        Edit4: TEdit;
        Edit5: TEdit;
        Name: TLabel;
        Artist: TLabel;
        Album: TLabel;
        Year: TLabel;
        Comment: TLabel;
        Remove: TBitBtn;
        Update: TBitBtn;
        OK: TBitBtn;
        procedure RemoveClick(Sender: TObject);
        procedure UpdateClick(Sender: TObject);
        procedure FormShow(Sender: TObject);
        procedure OKClick(Sender: TObject);
      private
        { Private declarations }
        FN : String;
      public
        { Public declarations }
        function ReadID3Tag(FileName: string): TID3Tag;
        function WriteID3Tag(FileName: string; ID3InfoTag: TID3Tag): Boolean;
        function RemoveID3Tag(FileName: string): Boolean;
        function ID3TagsAreEqual(ID3Tag1, ID3Tag2: TID3Tag): Boolean;
      end;
    var
      ID3Info: TID3Info;
      id3tag: tid3tag;implementationuses MP_List_Unit;{$R *.DFM}procedure TID3Info.RemoveClick(Sender: TObject);
    begin
      if FileExists(FN) then
         if RemoveID3Tag(FN) then
            begin
              MessageDlg('Remove ok!', mtInformation, [mbOK], 0);
              edit1.Text:='';
              edit2.Text:='';
              edit3.Text:='';
              edit4.Text:='';
              edit5.Text:='';
            end else MessageDlg('Remove failed!', mtError, [mbOK], 0);
    end;function TID3Info.ID3TagsAreEqual(ID3Tag1, ID3Tag2: TID3Tag): Boolean;
    begin
       with ID3Tag1 do
        if (string(ID3Tag2.Tag) <> string(Tag)) or
          (string(ID3Tag2.Songname) <> string(SongName)) or
          (string(ID3Tag2.Artist) <> string(Artist)) or
          (string(ID3Tag2.Album) <> string(Album)) or
          (string(ID3Tag2.Year) <> string(Year)) or
          (string(ID3Tag2.Comment) <> string(Comment)) or
          (ID3Tag2.Genre <> Genre) then Result := False
        else Result := True;
    end;function TID3Info.ReadID3Tag(FileName: string): TID3Tag;
    var
      F: file;
    begin
    {$I-}
      AssignFile(F, FileName);
      Reset(F, 1);
      Seek(F, Filesize(F) - SizeOf(TID3Tag));
      Result.Tag[1] := 'N';
      BlockRead(F, Result, SizeOf(TID3Tag));
      CloseFile(F);
    {$I+}
    end;function TID3Info.RemoveID3Tag(FileName: string): Boolean;
    var
      FileHandle: integer;
      attr:Integer;
    begin
    {$I-}
      attr:=FileGetAttr(FileName);
      FileSetAttr(FileName,faArchive);
      FileHandle := FileOpen(FileName, fmOpenReadWrite or fmShareDenyWrite);
      if FileHandle > 0 then
          if ID3Tag.Tag = 'TAG' then
            begin
              FileSeek(FileHandle, 0 - SizeOf(TID3Tag), 2);
              SetEndOfFile(FileHandle);
            end;
       FileClose(FileHandle);
       result := FileHandle <> 0;
       FileSetAttr(FileName,attr);
    {$I+}
    end;function TID3Info.WriteID3Tag(FileName: string; ID3InfoTag: TID3Tag): Boolean;
    var
      F: file;
      X: Integer;
      attr:Integer;
    begin
    {$I-}
      attr:=FileGetAttr(FileName);
      FileSetAttr(FileName,faArchive);
      AssignFile(F, FileName);
      Reset(F, 1);
      X:=0;
      if ReadID3Tag(FileName).Tag <> 'TAG' then Seek(F, FileSize(F))
      else Seek(F, FileSize(F) - SizeOf(TID3Tag));
      BlockWrite(F, ID3Tag, SizeOf(TID3Tag), X);
      Result := (X <> 0);
      CloseFile(F);
      FileSetAttr(FileName,attr);
    {$I+}
    end;procedure TID3Info.UpdateClick(Sender: TObject);
    var s: string;
    begin
      if FileExists(fn) then
       with ID3Tag do
         begin
           Tag := 'TAG';
           S := edit1.text;
           if length(S) > 30 then setlength(S, 30);
           StrPCopy(Songname, S);
           S := edit2.text;
           if length(S) > 30 then setlength(S, 30);
           StrPCopy(Artist, S);
           S := edit3.text;
           if length(S) > 30 then setlength(S, 30);
           StrPCopy(Album, S);
           S := edit4.text;
           if length(S) > 4 then setlength(S, 4);
           StrPCopy(Year, S);
           S := edit5.text;
           if length(S) > 30 then setlength(S, 30);
           StrPCopy(Comment, S);
           if WriteID3Tag(fn, ID3Tag)
              then MessageDlg('Update ok!', mtInformation, [mbOK], 0)
              else begin
                     MessageDlg('Update failed!', mtError, [mbOK], 0);
                     FormShow(nil);
                   end;
         end;
    end;procedure TID3Info.FormShow(Sender: TObject);
    begin
      FN := SongListForm.GetSelectedFileName;
      if FileExists(FN)
         then ID3Tag:=ReadID3Tag(FN)
         else begin
                MessageDlg('File cannot be found!', mtError, [mbOK], 0);
                PostMessage(Handle, WM_Close, 0, 0);
                Exit;
              end;
      if (ID3Tag.Tag = 'TAG') and (trim(ID3Tag.songname) <> '')  then
         begin
           //Display the Songname etc.. in the Label
           edit1.Text :=  Trim(ID3Tag.songname);
           edit2.Text :=  Trim(ID3Tag.Artist);
           edit3.Text :=  Trim(ID3Tag.Album);
           edit4.Text :=  Trim(ID3Tag.Year);
           edit5.Text :=  Trim(ID3Tag.Comment);
         end else
               begin
                 edit1.Text :=  ExtractFileName(FN);
                 edit2.Text :=  '';
                 edit3.Text :=  '';
                 edit4.Text :=  '';
                 edit5.Text :=  '';
               end;
    end;procedure TID3Info.OKClick(Sender: TObject);
    begin
      Close;
    end;end.
      

  3.   

    网上不是很多例子可以下载么?
    Google上N多呀http://lysoft.7u7.net
      

  4.   

    用文件流TFileStream的时候,如果你要打开的文件正在被另外一个进程所使用,那么它就会有问题。从你的代码来看(不是很完全)是没有什么问题的。我这里有一个读写ID3v1的library,如果你需要,留下你的E-mail。
      

  5.   

    >>不知道这段代码对我有不有帮助请大家看看
    >>...代码对自己有没帮助还问人家,人家哪知道对你有没帮助?强烈滴鄙视一下!
      

  6.   

    我不是专业做程序开发的,我只是一个业务员而已,不过也没有事
    我的问题多的是呢
    to unsigned(僵哥) 可不可以帮我搞定一下。
    还有好多的问题呢,只是在这上面发了也没有人回复正确过。
    》》代码对自己有没帮助还问人家,人家哪知道对你有没帮助?强烈滴鄙视一下!
      

  7.   

    人气太差了,我看DELPHI没意思再学下去了
      

  8.   

    有没有知道,track怎么做出来,我作的那个好象不对,只是会出来13,12这几个数.高手们帮帮忙吗
      

  9.   

    Track的意思是这首歌曲在它的专辑里排在第几首,这个值并不是每个ID3都会设置。
      

  10.   

    但是我的怎么不和操作系统的一样呢,我的是
    byte类型
      

  11.   

    Microsnow(冰火)
    我的EMAIL是:
    [email protected]
    [email protected]
    [email protected]
    [email protected]
    你发给我一个吗,标题用中文好吗?
    谢谢了!!!!!
    我的QQ是59965221