CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
花落谁家,你作主! 盛大widget设计大赛英雄榜
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  基础类

MP3播放

楼主flit()2002-04-18 22:57:44 在 VB / 基础类 提问

不用MP3控件如何播放MP3? 问题点数:100、回复次数:7Top

1 楼sonicdater(事过境迁,除了技术,我什么都没有了)回复于 2002-04-18 23:07:49 得分 0

这是一个   播放   MP3   的类:  
  ===================================================================  
  VERSION   1.0   CLASS  
  BEGIN  
      MultiUse   =   -1     'True  
      Persistable   =   0     'NotPersistable  
      DataBindingBehavior   =   0     'vbNone  
      DataSourceBehavior     =   0     'vbNone  
      MTSTransactionMode     =   0     'NotAnMTSObject  
  END  
  Attribute   VB_Name   =   "clsID3"  
  Attribute   VB_GlobalNameSpace   =   False  
  Attribute   VB_Creatable   =   True  
  Attribute   VB_PredeclaredId   =   False  
  Attribute   VB_Exposed   =   False  
  Attribute   VB_Description   =   "Allows   manipulation   of   the   ID3"  
  Attribute   VB_Ext_KEY   =   "SavedWithClassBuilder6"   ,"Yes"  
  Attribute   VB_Ext_KEY   =   "Top_Level"   ,"Yes"  
  Private   mvarFilename   As   String  
  Private   mvarArtist   As   String  
  Private   mvarTitle   As   String  
  Private   mvarAlbum   As   String  
  Private   mvarComment   As   String  
  Private   mvarGenre   As   Integer  
  Private   mvarYear   As   String  
  Private   tagData   As   String   *   128  
  Public   isActive   As   Boolean  
   
  Public   Property   Let   Genre(ByVal   vData   As   Integer)  
          If   (Len(Dir(mvarFilename)))   =   0   Then   Exit   Property  
          If   vData   <   0   Or   vData   >   255   Then   vData   =   255  
          Mid(tagData,   128,   1)   =   Chr(vData)  
          mvarGenre   =   vData  
  End   Property  
   
  Public   Property   Get   Genre()   As   Integer  
          If   (Len(Dir(mvarFilename)))   =   0   Then   Exit   Property  
          Genre   =   mvarGenre  
  End   Property  
   
   
   
  Public   Property   Let   Comment(ByVal   vData   As   String)  
          If   (Len(Dir(mvarFilename)))   =   0   Then   Exit   Property  
          If   Len(vData)   >   30   Then   vData   =   Left(vData,   30)   'If   too   big,   trim   to   30  
          If   Len(vData)   <   30   Then   vData   =   vData   &   String(30   -   Len(vData),   Chr(0))   'If   too   small,   fill   the   rest   with   nulls  
          Mid(tagData,   98,   30)   =   vData  
          mvarComment   =   vData  
  End   Property  
   
  Public   Property   Get   Comment()   As   String  
          If   (Len(Dir(mvarFilename)))   =   0   Then   Exit   Property  
          Comment   =   mvarComment  
  End   Property  
   
   
   
  Public   Property   Let   Album(ByVal   vData   As   String)  
          If   (Len(Dir(mvarFilename)))   =   0   Then   Exit   Property  
          If   Len(vData)   >   30   Then   vData   =   Left(vData,   30)   'If   too   big,   trim   to   30  
          If   Len(vData)   <   30   Then   vData   =   vData   &   String(30   -   Len(vData),   Chr(0))   'If   too   small,   fill   the   rest   with   nulls  
          Mid(tagData,   64,   30)   =   vData  
          mvarAlbum   =   vData  
  End   Property  
   
  Public   Property   Get   Album()   As   String  
          If   (Len(Dir(mvarFilename)))   =   0   Then   Exit   Property  
          Album   =   mvarAlbum  
  End   Property  
   
   
   
  Public   Property   Let   Title(ByVal   vData   As   String)  
          If   (Len(Dir(mvarFilename)))   =   0   Then   Exit   Property  
          If   Len(vData)   >   30   Then   vData   =   Left(vData,   30)   'If   too   big,   trim   to   30  
          If   Len(vData)   <   30   Then   vData   =   vData   &   String(30   -   Len(vData),   Chr(0))   'If   too   small,   fill   the   rest   with   nulls  
          Mid(tagData,   4,   30)   =   vData  
          mvarTitle   =   vData  
  End   Property  
   
  Public   Property   Get   Title()   As   String  
          If   (Len(Dir(mvarFilename)))   =   0   Then   Exit   Property  
          Title   =   mvarTitle  
  End   Property  
   
   
   
  Public   Property   Let   Artist(ByVal   vData   As   String)  
          If   (Len(Dir(mvarFilename)))   =   0   Then   Exit   Property  
          If   Len(vData)   >   30   Then   vData   =   Left(vData,   30)   'If   too   big,   trim   to   30  
          If   Len(vData)   <   30   Then   vData   =   vData   &   String(30   -   Len(vData),   Chr(0))   'If   too   small,   fill   the   rest   with   nulls  
          Mid(tagData,   34,   30)   =   vData  
          mvarArtist   =   vData  
  End   Property  
   
  Public   Property   Get   Artist()   As   String  
          If   (Len(Dir(mvarFilename)))   =   0   Then   Exit   Property  
          Artist   =   mvarArtist  
  End   Property  
   
   
   
  Public   Property   Let   Filename(ByVal   vData   As   String)  
          Dim   fileNum   As   Long,   filePos   As   Long  
           
          If   Len(Dir(vData))   =   0   Then  
                  GoTo   WRONG  
          Else  
                  If   UCase(Right(vData,   4))   <>   ".MP3"   Then   GoTo   WRONG  
                  fileNum   =   FreeFile  
                  filePos   =   FileLen(vData)   -   127  
                  If   filePos   >   0   Then  
                          Open   vData   For   Binary   As   #fileNum  
                                  Get   #fileNum,   filePos,   tagData  
                          Close   #fileNum  
                          If   Left(tagData,   3)   <>   "TAG"   Then   GoTo   WRONG  
                           
                          mvarTitle   =   Replace(Trim(Mid(tagData,   4,   30)),   Chr(0),   "")  
                          mvarArtist   =   Replace(Trim(Mid(tagData,   34,   30)),   Chr(0),   "")  
                          mvarAlbum   =   Replace(Trim(Mid(tagData,   64,   30)),   Chr(0),   "")  
                          mvarYear   =   Replace(Trim(Mid(tagData,   94,   4)),   Chr(0),   "")  
                          mvarComment   =   Replace(Trim(Mid(tagData,   98,   30)),   Chr(0),   "")  
                          mvarGenre   =   Asc(Mid(tagData,   128,   1))  
                  Else  
                          GoTo   WRONG  
                  End   If  
          End   If  
           
          isActive   =   True  
          mvarFilename   =   vData  
          Exit   Property  
  WRONG:   '   Jumps   here   if   bad   file  
          isActive   =   False  
          mvarFilename   =   ""  
  End   Property  
   
  Public   Property   Get   Filename()   As   String  
          Filename   =   mvarFilename  
  End   Property  
   
   
   
  Public   Property   Let   Year(ByVal   vData   As   String)  
          If   (Len(Dir(mvarFilename)))   =   0   Then   Exit   Property  
          If   Len(vData)   >   4   Then   vData   =   Left(vData,   4)   'If   too   big,   trim   to   30  
          If   Len(vData)   <   4   Then   vData   =   vData   &   String(4   -   Len(vData),   Chr(0))   'If   too   small,   fill   the   rest   with   nulls  
          Mid(tagData,   94,   4)   =   vData  
          mvarYear   =   vData  
  End   Property  
   
  Public   Property   Get   Year()   As   String  
          If   (Len(Dir(mvarFilename)))   =   0   Then   Exit   Property  
          Year   =   mvarYear  
  End   Property  
   
   
   
  Public   Function   SaveTag()   As   String  
          Dim   errDesc   As   String   '   Error   description  
          Dim   fileNum   As   Long,   filePos   As   Long  
          Dim   fileData   As   String  
           
          If   Len(Dir(mvarFilename))   =   0   Then  
                  errDesc   =   "File   not   found"  
                  GoTo   WRONG  
          Else  
                  If   UCase(Right(mvarFilename,   4))   <>   ".MP3"   Then   errDesc   =   "Wrong   file   extension.   Must   be   .mp3":   GoTo   WRONG  
                  fileNum   =   FreeFile  
                  fileData   =   String(FileLen(mvarFilename),   Chr(0))   'Buffer  
                   
                  If   FileLen(mvarFilename)   >   128   Then  
                          Open   mvarFilename   For   Binary   As   #fileNum  
                                  Get   #fileNum,   1,   fileData  
                          Close   #fileNum  
                          If   Left(Right(fileData,   128),   3)   <>   "TAG"   Then   GoTo   WRONG  
                           
                          Mid(fileData,   Len(fileData)   -   127)   =   tagData  
   
                          fileNum   =   FreeFile  
                          Open   mvarFilename   For   Binary   As   #fileNum  
                                  Put   #fileNum,   1,   fileData  
                          Close   #fileNum  
                  Else  
                          GoTo   WRONG  
                  End   If  
          End   If  
           
          Exit   Function  
  WRONG:   'Go   here   if   error   writing   to   file  
          isActive   =   False  
          mvarFilename   =   ""  
          SaveTag   =   errDesc  
  End   Function  
  ===================================================================  
  它的用法:  
   
  Dim   MP3   As   New   clsID3  
  MP3.Filename   =   "c:\ChrisRea.mp3"  
   
  If   MP3.isActive   =   True   Then  
  'Get   ID3   information   about   MP3  
  MsgBox   "MP3   Info:"   &   vbCrLf   &   vbCrLf   &   _  
  "Title:"   &   vbTab   &   MP3.Title   &   vbCrLf   &   _  
  "Artist:"   &   vbTab   &   MP3.Artist   &   vbCrLf   &   _  
  "Album:"   &   vbTab   &   MP3.Album   &   vbCrLf   &   _  
  "Year:"   &   vbTab   &   MP3.Year   &   vbCrLf   &   _  
  "Genre:"   &   vbTab   &   MP3.Genre   &   vbCrLf   &   _  
  "Comment:"   &   vbTab   &   MP3.Comment  
   
  'Change   the   ID3   information  
  MP3.Artist   =   "New   Artist   2"  
  MP3.Title   =   "New   Title   2"  
  MP3.Album   =   "Some   Album   2"  
  MP3.Comment   =   "Created   using   clsID3   2"  
  MP3.Year   =   "2000"  
  MP3.Genre   =   54  
   
  MP3.SaveTag   'Saves   the   new   ID3   information  
   
  Else   'Error   opening   MP3   file  
  MsgBox   "Invalid   MP3   file"  
  End   If  
  ===================================================================  
  Top

2 楼sleilei(雷磊)回复于 2002-04-18 23:36:31 得分 100

不错啊,就是太麻烦了,直接用API就可以(假设播放D:\MP3\1.MP3)  
  在模块中添加以下代码:  
  Public   Declare   Function   mciSendString   Lib   "winmm.dll"   Alias   "mciSendStringA"   (ByVal   lpstrCommand   As   String,   ByVal   lpstrReturnString   As   String,   ByVal   uReturnLength   As   Long,   ByVal   hwndCallback   As   Long)   As   Long  
  在窗体中加入以下代码:  
  Dim   FileName   As   String  
   
  Private   Function   Play_MP3()  
          filename="d:\mp3\1.mp3"  
          mciSendString   "Close   MM",   0,   0,   0          
          mciSendString   "Open   "   &   FileName   &   "   Alias   MM",   0,   0,   0  
          mciSendString   "Play   MM",   0,   0,   0  
  End   Function  
  Private   Sub   Play_Click()  
          FileName   =   Text1.Text  
          Play_MP3  
  End   Sub  
  还可以吗?别忘了给分!  
  其实直接用MCI32.ocx就可以直接播放MP3文件,非常方便。  
  Top

3 楼uguess(天地间,有我在行走!)回复于 2002-04-18 23:36:34 得分 0

TO   :sonicdater(发呆呆)    
   
      呵呵,没看出这个类是怎么实现“播放”MP3的!注意是“播放”,不是获得里面的信息!  
   
  Top

4 楼Mike_sun(漠风)回复于 2002-04-18 23:43:48 得分 0

heheTop

5 楼TechnoFantasy((VB MVP)www.applevb.com)回复于 2002-04-19 08:54:52 得分 0

现在的Media   Player   7.0   以上都支持mp3,直接用Media控件或者API就可以。Top

6 楼gump2000(阿甘)回复于 2002-04-19 08:59:43 得分 0

同意楼上的阿:)  
  Top

7 楼baguijin999()回复于 2002-04-19 09:09:37 得分 0

www.21code.com   中的多媒体方面有很多的例程,可以参照一下。Top

相关问题

  • 如何实现delphi中的mp控件来播放DVD格式的视频啊???
  • 高手指教:怎样用DELPHI自带的MP控件播放DVD文件啊?
  • 播放器无法播放!
  • VCD播放
  • 在线播放
  • MP3播放
  • 播放音乐
  • 要播放flash
  • 视频播放~
  • 随机播放

关键词

  • mp3
  • vb
  • vdata
  • mvarfilename
  • tagdata
  • filenum
  • stringprivate
  • isactive
  • 播放
  • vbtab

得分解答快速导航

  • 帖主:flit
  • sleilei

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo