elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Arreglado, de nuevo, el registro del warzone (wargame) de EHN


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Como reproducir un MP3 en Visual Basic?
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 2 [3] Ir Abajo Respuesta Imprimir
Autor Tema: Como reproducir un MP3 en Visual Basic?  (Leído 24,080 veces)
ShadowHoc

Desconectado Desconectado

Mensajes: 8



Ver Perfil
Re: Como reproducir un MP3 en Visual Basic?
« Respuesta #20 en: 21 Julio 2013, 21:21 pm »


    4 CommandButton: Command1 (Play) , Command2(stop) , Command3 (Pause) y Command4 (Abrir archivo)
    Un Commondialog1
    Un Label1: Para mostrar el Path


Código:
    Option Explicit  
    'Función Api GetShortPathName para obtener _ 
    los paths de los archivos en formato corto 
    Private Declare Function GetShortPathName _ 
        Lib "kernel32" _ 
        Alias "GetShortPathNameA" ( _ 
            ByVal lpszLongPath As String, _ 
            ByVal lpszShortPath As String, _ 
            ByVal lBuffer As Long) As Long 
     
    'Función Api mciExecute para reproducir los archivos de música 
    Private Declare Function mciExecute _ 
        Lib "winmm.dll" ( _ 
            ByVal lpstrCommand As String) As Long 
    Dim ret As Long, path As String 
     
    'Le pasamos el comando Play 
    Private Sub Command1_Click() 
        ejecutar ("Play ") 
        Habilitar "Play" 
    End Sub 
     
    Private Sub Command2_Click() 
        'Le pasamos el comando Stop 
        ejecutar ("Stop ") 
        Habilitar "Stop" 
    End Sub 
     
    'Le pasamos el comando Pause 
    Private Sub Command3_Click() 
        ejecutar ("Pause ") 
        Habilitar "Pause" 
    End Sub 
     
    'Le pasamos el comando Close a MciExecute para cerrar el dispositivo 
    Private Sub Form_Unload(Cancel As Integer) 
        mciExecute "Close All" 
    End Sub 
     
    'Botón para abrir seleccionar los archivos de audio 
    Private Sub Command4_Click() 
        With CommonDialog1 
            .Filter = "Archivos Wav|*.wav|Archivos Mp3|*.mp3|Archivos MIDI|*.mid" 
            .ShowOpen 
            If .FileName = "" Then 
                Habilitar "Iniciar" 
                Exit Sub 
            Else 
                'Le pasamos a la sub que obtiene con _ 
                el Api GetShortPathName el nombre corto del archivo 
                PathCorto .FileName 
                Label1 = .FileName 
                'cerramos todo 
                mciExecute "Close All" 
                'Para Habilitar y deshabilitar botones 
                Habilitar "Stop" 
            End If 
        End With 
    End Sub 
     
    'Sub que obtiene el path corto del archivo a reproducir 
    Private Sub PathCorto(archivo As String) 
    Dim temp As String * 250 'Buffer 
        path = String(255, 0) 
        'Obtenemos el Path corto 
        ret = GetShortPathName(archivo, temp, 164) 
        'Sacamos los nulos al path 
        path = Replace(temp, Chr(0), "") 
    End Sub 
     
    'Procedimiento que ejecuta el comando con el Api mciExecute 
    '************************************************************ 
    Private Sub ejecutar(comando As String) 
        If path = "" Then MsgBox "Error", vbCritical: Exit Sub 
        'Llamamos a mciExecute pasandole un string que tiene el comando y la ruta 
     
        mciExecute comando & path 
     
    End Sub 
     
    Private Sub Form_Load() 
        Command1.Caption = "Play >>" 
        Command2.Caption = "Stop ||||" 
        Command3.Caption = "Pause ||" 
        Command4.Caption = ":::: Abrir archivo de música ::::" 
        Habilitar "Iniciar" 
        Label1 = "": Label1.AutoSize = True 
    End Sub 
     
    Private Sub Habilitar(Accion As String) 
        Select Case Accion 
            Case "Iniciar" 
                Command1.Enabled = False 
                Command2.Enabled = False 
                Command3.Enabled = False 
            Case "Play" 
                Command1.Enabled = False 
                Command2.Enabled = True 
                Command3.Enabled = True 
            Case "Stop" 
                Command1.Enabled = True 
                Command2.Enabled = False 
                Command3.Enabled = False 
            Case "Pause" 
                Command1.Enabled = True 
                Command2.Enabled = True 
                Command3.Enabled = False 
        End Select 
    End Sub 

Fuente : http://www.recursosvisualbasic.com.ar/htm/listado-api/api-53-mciexecute.htm


Espero que les sirva....aunque un poco tarde xD


En línea

Páginas: 1 2 [3] Ir Arriba Respuesta Imprimir 

Ir a:  
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines