Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - Общий форум

Страница: 1 |

 

  Вопрос: MPTime Добавлено: 03.10.08 15:22  

Автор вопроса:  VβÐUηìt | Web-сайт: смекаешь.рф
Простой, тупой и частозадаваемый вопрос, но он все же у меня возник: дан mp3-файл. Нужно узнать, сколько времени он длится. Желательно без декодирования и прочей мути.



Заранее благодарен.

Ответить

  Ответы Всего ответов: 2  

Номер ответа: 1
Автор ответа:
 Боцман



ICQ: 295725312 

Вопросов: 53
Ответов: 830
 Web-сайт: Rus-Skipper.narod.ru
 Профиль | | #1
Добавлено: 03.10.08 17:29
В форме.
Option Explicit
  Dim accMP3Info As MP3Info
Private Sub Form_Load()
  Me.OLEDropMode = 1
  Me.Caption = "Тащи на форму файл МР3"
End Sub

Private Sub Form_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Data.GetFormat(vbCFFiles) = True Then
Dim c As Long
For c = 1 To Data.Files.Count
MP3FileName = Data.Files(c)
Next c
End If
 getMP3Info MP3FileName, accMP3Info
 Print accMP3Info.LENGTH
End Sub

в форме
Option Explicit

Public MP3FileName As String

Public Type VBRinfo
  VBRrate As String
  VBRlength As String
End Type

Public Type MP3Info
  BITRATE As String
  CRC As String
  LAYER As String
  LENGTH As String
  MPEG As String
End Type
Private MP3Length As Long

Public Sub getMP3Info(ByVal lpMP3File As String, ByRef lpMP3Info As MP3Info)
  Dim Buf As String * 4096
  Dim infoStr As String * 3
  Dim lpVBRinfo As VBRinfo
  Dim tmpByte As Byte
  Dim tmpNum As Byte
  Dim i As Integer
  Dim designator As Byte
  Dim baseFreq As Single
  Dim vbrBytes As Long
  
  Open lpMP3File For Binary As #1
    Get #1, 1, Buf
  Close #1
  
  For i = 1 To 4092
    If Asc(Mid(Buf, i, 1)) = &HFF Then
      tmpByte = Asc(Mid(Buf, i + 1, 1))
      If Between(tmpByte, &HF2, &HF7) Or Between(tmpByte, &HFA, &HFF) Then
        Exit For
      End If
    End If
  Next i
  If i = 4093 Then
    MsgBox "Not a MP3 file...", vbCritical, "Error..."
  Else
    infoStr = Mid(Buf, i + 1, 3)
    'Getting info from 2nd byte(MPEG,Layer type and CRC)
    tmpByte = Asc(Mid(infoStr, 1, 1))
    
    'Getting CRC info
    If ((tmpByte Mod 16) Mod 2) = 0 Then
      lpMP3Info.CRC = "Yes"
    Else
      lpMP3Info.CRC = "No"
    End If
    
    'Getting MPEG type info
    If Between(tmpByte, &HF2, &HF7) Then
      lpMP3Info.MPEG = "MPEG 2.0"
      designator = 1
    Else
      lpMP3Info.MPEG = "MPEG 1.0"
      designator = 2
    End If
    
    'Getting layer info
    If Between(tmpByte, &HF2, &HF3) Or Between(tmpByte, &HFA, &HFB) Then
      lpMP3Info.LAYER = "layer 3"
    Else
      If Between(tmpByte, &HF4, &HF5) Or Between(tmpByte, &HFC, &HFD) Then
        lpMP3Info.LAYER = "layer 2"
      Else
        lpMP3Info.LAYER = "layer 1"
      End If
    End If
    tmpByte = Asc(Mid(infoStr, 2, 1))
    
    tmpNum = tmpByte \ 16 Mod 16
    If designator = 1 Then
      If tmpNum < &H8 Then
        lpMP3Info.BITRATE = tmpNum * 8
      Else
        lpMP3Info.BITRATE = 64 + (tmpNum - 8) * 16
      End If
    Else
      If tmpNum <= &H5 Then
        lpMP3Info.BITRATE = (tmpNum + 3) * 8
      Else
        If tmpNum <= &H9 Then
          lpMP3Info.BITRATE = 64 + (tmpNum - 5) * 16
        Else
          If tmpNum <= &HD Then
            lpMP3Info.BITRATE = 128 + (tmpNum - 9) * 32
          Else
            lpMP3Info.BITRATE = 320
          End If
        End If
      End If
    End If
    MP3Length = FileLen(lpMP3File) \ (Val(lpMP3Info.BITRATE) / 8) \ 1000
    If Mid(Buf, i + 36, 4) = "Xing" Then
      lpMP3Info.LENGTH = lpVBRinfo.VBRlength
    Else
      lpMP3Info.LENGTH = MP3Length
    End If
  End If
End Sub

Public Function Between(ByVal accNum As Byte, ByVal accDown As Byte, ByVal accUp As Byte) As Boolean
  If accNum >= accDown And accNum <= accUp Then
    Between = True
  Else
    Between = False
  End If
End Function

Ответить

Номер ответа: 2
Автор ответа:
 VβÐUηìt



Вопросов: 246
Ответов: 3333
 Web-сайт: смекаешь.рф
 Профиль | | #2
Добавлено: 03.10.08 17:35
Благодарю!

Ответить

Страница: 1 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам