Buenas les vengo a traer un codigo muy lindo,util y creo que no es dificil ah y sobre todo funcional.Espero que les sirva.
1 - Creamos Un Modulo de Clase Con el Nombre: clsMP3Player
2 - Adentro de este nuevo Modulo de clase agregamos este codigo:
Cita:
Option Explicit
Private mvarmp3file As String
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 Declare Function GetShortPathName Lib "Kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long
Dim mVolume As Integer
Public Sub pauseMP3()
mciSendString "pause audio1", 0, 0, 0
End Sub
Public Sub playMP3()
Dim rtn As Long
Dim filename As String
Dim lngRes As Long, strPath As String
Public Property Let mp3file(ByVal vData As String)
mvarmp3file = vData
End Property
Public Property Get mp3file() As String
mp3file = mvarmp3file
End Property
Public Property Let Volume(ByVal nVolume As Integer)
mciSendString "setaudio audio1 volume to " & nVolume, "", 0, 0
mVolume = nVolume
End Property
Public Property Get Volume() As Integer
Volume = mVolume
End Property
'setaudio MP3 volume to " + NewVolume
Public Function Position(secs As Boolean) As String
'Returns the track's current position as "mm:ss".
'Returns tracks's current position in seconds if secs = True
Static P As String * 30
Dim sec As Integer
Dim mins As Integer
If secs Then
Position = sec
Else
If sec < 60 Then Position = "0:" & Format(sec, "00")
If sec > 59 Then
mins = Int(sec / 60)
sec = sec - (mins * 60)
Position = Format(mins, "00") & ":" & Format(sec, "00")
End If
End If
End Function
Public Function TrackLength(secs As Boolean) As String
'Returns the track's length as "mm:ss".
'Returns tracks's length in seconds if secs = True
Static L As String * 30
Dim sec As Integer
Dim mins As Integer
mciSendString "set audio1 Time Format milliseconds", "", 0, 0
mciSendString "status audio1 length", L, Len(L), 0
sec = Round(Val(Mid$(L, 1, Len(L))) / 1000)
If secs Then
TrackLength = sec
Else
If sec < 60 Then
TrackLenghth = "0:" & Format(sec, "00")
Else
mins = Int(sec / 60)
sec = sec - (mins * 60)
TrackLength = Format(mins, "00") & ":" & Format(sec, "00")
End If
End If
End Function
Public Function IsItPlaying() As Boolean
'Returns true if the file is playing. False otherwise.
4 - Para terminar creas un modulo con el nombre: Mod_MP3
y adentro de este ponemos:
Cita:
Option Explicit
Public Const SND_SYNC = &H0 ' SINCRONO
Public Const SND_ASYNC = &H1 ' ASINCRONO
Public Const SND_NODEFAULT = &H2 ' silence not default, if sound not found
Public Const SND_LOOP = &H8 ' loop the sound until next sndPlaySound
Public Const SND_NOSTOP = &H10 ' don't stop any currently playing sound
Dim CSTRM As New Collection
Public bBass As Boolean
Public Function InitializeBass()
' Check that BASS 1.0 was loaded
If BASS_GetStringVersion <> "1.1" Then
LogError "Wrong BASS version number -> 1.1"
bBass = False
End If
' Initialize digital sound - default device, 44100hz, stereo, 16 bits
If BASS_Init(-1, 44100, BASS_DEVICE_LEAVEVOL, frmMain.hWnd) = BASSFALSE Then
LogError "Can't init sound system"
bBass = False
Exit Function
End If
' Start digital output
If BASS_Start = BASSFALSE Then
LogError "Can't start digital output"
bBass = False
Exit Function
End If
bBass = True
End Function
Public Function ShutDownBass()
If bBass Then
Dim iX As Integer
' Stop digital output
BASS_Stop
' Free the stream
For iX = 1 To CSTRM.Count
BASS_StreamFree CSTRM(iX)
Next iX
' Close digital sound system
BASS_Free
' Release HStream collection
Set CSTRM = Nothing
End If
End Function
Public Sub LoadSounds()
If bBass Then
Dim iX As Integer
Dim StreamHandle As Long
frmCargando.MP3Files.Pattern = "*.mp3"
frmCargando.MP3Files.Path = DirSound
'Load MP3s
For iX = 0 To frmCargando.MP3Files.ListCount - 1
StreamHandle = BASS_StreamCreateFile(BASSFALSE, DirSound & frmCargando.MP3Files.List(iX), 0, 0, 0)
If StreamHandle = 0 Then
LogError "Can't create stream: " & frmCargando.MP3Files.List(iX)
Else
Call CSTRM.Add(StreamHandle, frmCargando.MP3Files.List(iX))
End If
Next iX
'Load WAVs
frmCargando.MP3Files.Pattern = "*.wav"
For iX = 0 To frmCargando.MP3Files.ListCount - 1
StreamHandle = BASS_StreamCreateFile(BASSFALSE, DirSound & frmCargando.MP3Files.List(iX), 0, 0, 0)
If StreamHandle = 0 Then
LogError "Can't create stream: " & frmCargando.MP3Files.List(iX)
Else
Call CSTRM.Add(StreamHandle, frmCargando.MP3Files.List(iX))
End If
Next iX
End If
End Sub
Public Function PlaySound(sFile As String, Optional bLoop As Boolean)
If bBass And Fx = 0 Then
'Play stream, not flushed
If bLoop Then
If BASS_ChannelIsActive(CSTRM(sFile)) = BASSFALSE Then
If BASS_StreamPlay(CSTRM(sFile), BASSFALSE, BASS_SAMPLE_LOOP) = BASSFALSE Then _
LogError "Can't play stream: " & sFile
End If
Else
Call BASS_ChannelStop(CSTRM(sFile))
If BASS_StreamPlay(CSTRM(sFile), BASSFALSE, 0) = BASSFALSE Then _
LogError "Can't play stream: " & sFile
End If
End If
End Function
Public Function StopSound(sFile As String)
If bBass Then
' Stop the stream
If BASS_ChannelIsActive(CSTRM(sFile)) = BASSTRUE Then
Call BASS_ChannelStop(CSTRM(sFile))
End If
End If
End Function
¿Cómo Usarlo?
Facil:
Cita:
Set MP3P = New clsMP3Player
MP3P.mp3file = App.Path + "MP3musica.mp3"
MP3P.stopMP3
MP3P.playMP3
MP3P.Volume = 1000
Ahi tienen los controles basicos, para controlar la Musica
Fuente: GS-Zone
__________________
Última edición por Luque; 16-nov-2008 a las 00:54.
El siguiente usuario ha dado las gracias a Luque y considera util este tema:
eso es lo qe tengo qe poner para andar el reproductor?
1-Que no se entiende de que lo saco de GS-Zone? hay algo de malo? :S
2->.< Vos tenes que poner por ejemplo cuando queiras musica:
Código:
Set MP3P = New clsMP3Player
MP3P.mp3file = App.Path + "MP3musica.mp3"
MP3P.playMP3
Por ejemplo, al iniciar podes poner eso, y te iicia con la musica MP3 que vos hayas puesto.
Cita:
Iniciado por Blade
Mira luqi, si keres que tu post sea agradecido, ponelo completo con formulario bien armado, con todo listo y ai te van a agradecer y no criticar...
El posteo sistema de audio mp3, No un sistema de Reproductor de MP3.
Personalmente creo que queda horrible un formulario para reproducir mp3, no combina para nada con la estetica del ao :S el sistema este esta para que desactives los MIDIS y actives los mp3, cosa que no es nada dificil.
Gracias stan te considero como uno de los mejores programadores y la fuente ha que ponerla es regla de todo foro,aparte sino pones la fuente queda como que lo estas haciendo vs y tas tomando el merito de otra persona que fue la que verdaderamente hizo todo el trabajo