Leer archivos MP3 co Visual Basic 6

Necesito saber como puedo hacer para leer archios mp3 utilizando visual basic

1 Respuesta

Respuesta
1
Para ésto necesitas:
5 Botones de nombre "Command1",2,3,4 y 5
El 1 de etiqueta "Abrir archivo MP3"
El 2 de etiqueta "Pausa"
El 3 de etiqueta "Cerrar"
El 4 de etiqueta "Regresar"
El 5 de etiqueta "Salir"
1 Checkbox de nombre "Check1", si está marcado permitirá repetir la canción.
1 Timer de nombre "Timer1" en la propiedad interval coloca "1"
Dibujas los objetos en un formulario form1 y copias lo siguiente:
Private Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal uLength As Long) As Long
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private 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
Private mmOpen As String, sec As Integer, mins As Integer
Dim nFileName As String
Public Function MP3Play(wndHandle As Long, sFileName As String)
Dim cmdToDo As String * 255
Dim dwReturn As Long
Dim ret As String * 128
Dim tmp As String * 255
Dim lenShort As Long
Dim ShortPathAndFie As String, glo_HWND As Long
If Dir(sFileName) = "" Then
mmOpen = "Error with input file"
Exit Function
End If
lenShort = GetShortPathName(sFileName, tmp, 255)
ShortPathAndFie = Left$(tmp, lenShort)
glo_HWND = wndHandle
cmdToDo = "open " & ShortPathAndFie & " type MPEGVideo Alias MP3Play"
dwReturn = mciSendString(cmdToDo, 0&, 0&, 0&)
If dwReturn <> 0 Then 'not success
mciGetErrorString dwReturn, ret, 128
mmOpen = ret
MsgBox ret, vbCritical
Exit Function
End If
mmOpen = "Success"
mciSendString "play MP3Play", 0, 0, 0
End Function
Public Function MP3Pause()
mciSendString "pause MP3Play", 0, 0, 0
End Function
Public Function MP3UnPause()
mciSendString "play MP3Play", 0, 0, 0
End Function
Public Function MP3Stop() As String
mciSendString "stop MP3Play", 0, 0, 0
mciSendString "close MP3Play", 0, 0, 0
End Function
Private Sub Check1_Click()
Timer1 = Not Timer1
If Timer1 Then Check1.Value = 1 Else Check1.Value = 0
End Sub
Private Sub Command1_Click()
Command1.Enabled = False
Command5.Enabled = False
Open_file
End Sub
Private Sub Command2_Click()
If Command2.Caption = "Pause" Then
Command2.Caption = "Play"
MP3Pause
Else
Command2.Caption = "Pause"
MP3UnPause
End If
End Sub
Private Sub Command3_Click()
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command1.Enabled = True
Command2.Caption = "Pause"
MP3Stop
End Sub
Private Sub Command4_Click()
mciSendString "stop MP3Play", 0, 0, 0
mciSendString "play MP3Play from 0", 0, 0, 0
Command2.Caption = "Pause"
End Sub
Private Sub Command5_Click()
Unload Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
MP3Stop
End Sub
Private Sub Open_file()
Dim cderr As Long
OFN.lStructSize = 76&
OFN.hwndOwner = Form1.hWnd
OFN.lpstrFilter = "mp3 (*.mp3)" + Chr(0) + "*.*" + Chr(0) + Chr(0)
OFN.lpstrCustomFilter = String(256, Chr(0))
OFN.nMaxCustFilter = 256
OFN.lpstrFile = "" + String(512, Chr(0))
OFN.nMaxFile = 512
OFN.lpstrFileTitle = String(256, Chr(0))
OFN.nMaxFileTitle = 256
OFN.flags = OFN_FILEMUSTEXIST + OFN_HIDEREADONLY
'************
DoEvents
'************
If GetOpenFileName(OFN) Then
OFN.lpstrFile = Mid(OFN.lpstrFile, 1.
El codigo que me diste esta bien. La falla se presentaba cuando dejaba en enabled del timer1 en true al iniciar el programa.Todo bien me sirvio de mucho. Te agradezco la ayuda.
A la respuesta anterior le falta lo siguiente despues de la ","
InStr(OFN. LpstrFile, Chr(0)) - 1)
nFileName = OFN.lpstrFile
OFN.lpstrFileTitle = Mid(OFN.lpstrFileTitle, 1, InStr(OFN.lpstrFileTitle, Chr(0)) - 1)
InitialDir = Left(OFN.lpstrFile, Len(OFN.lpstrFile) - Len(OFN.lpstrFileTitle))
Else
cderr = CommDlgExtendedError
GoTo ex
End If
MP3Play hWnd, nFileName
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
Exit Sub
ex:
Command1.Enabled = True
Command5.Enabled = True
End Sub
Public Function IsPlaying() As Boolean
Static s As String * 30
mciSendString "status MP3Play mode", s, Len(s), 0
IsPlaying = (Mid$(s, 1, 7) = "playing")
End Function
Private Sub Timer1_Timer()
If IsPlaying = False And Command1.Enabled = False And Command2.Caption = "Pause" Then Command4_Click
End Sub
luego en un módulo de nombre "Module1" lo siguiente:
Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Public Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
Public FileOP As String
Public Const OFN_FILEMUSTEXIST = &H1000
Public Const OFN_HIDEREADONLY = &H4
Public OFN As OPENFILENAME
Public Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Lo ejecute y todo bien por el unico detalle fue cuando activo el check me genera un error que dice error 28 en tiempo de ejecución. especi de pila insuficiente. ¿A que se debe este error?
¿Lo utilizas para que se active al terminar la canción.?
He probado nuevamente la aplicacion y no genera el error que mencionas.
Ejecuta la aplicación en modo de depuración con F8 y fíjate donde genera el error talvez haz copiado un espacio de más, o no dejado un espacio donde debería haberlo.
Se utiliza este check para reiniciar el archivo, si el valor está en "1" osea verdadero, lo reinicia, si no no lo hace.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas