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

 

 


Tema destacado: Introducción a la Factorización De Semiprimos (RSA)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  mciSendString
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: mciSendString  (Leído 2,651 veces)
CsarGR

Desconectado Desconectado

Mensajes: 47


Ver Perfil
mciSendString
« en: 5 Mayo 2007, 20:05 pm »

¿Alguien sabe como utilizar el "mciSendString"?
Mi intencion es la de reproducir varios .wav con el.
Por el momento no he sido capaz de trabajar con el, agradeceria cualquier ayuda con "mciSendString"


Gracias


En línea

~~
Ex-Staff
*
Desconectado Desconectado

Mensajes: 2.981


Ver Perfil WWW
Re: mciSendString
« Respuesta #1 en: 5 Mayo 2007, 20:18 pm »

Hola, mira un ejemplo para hacer sonar una cancion

Código:
'módulo:

Declare Function mciExecute Lib "winmm.dll" (ByVal lpstrCommand As String) As Long

'formulario:

Private Sub Command1_Click()
    iResult = mciExecute("Play c:\windows\ringin.wav")
End Sub

El archivo tiene q ser Wav o Midi





Y otro ejemplo de mciSendString de la api guide:

Código:
'This project needs a Common Dialog box, named 'CDBox'
'  (To add the Common Dialog Box to your tools menu, go to Project->Components (or press CTRL-T)
'   and select Microsoft Common Dialog control)
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
Dim Alias As String
Private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Const PlayTime = 10
    'Set the common dialog box' title
    CDBox.DialogTitle = "Choose your midi-file"
    'Set the filter
    CDBox.Filter = "Midi-files (*.mid)|*.mid"
    'Show the 'Open File'-dialog
    CDBox.ShowOpen
    'Extract an alias from the file
    Alias = Left$(CDBox.FileTitle, Len(CDBox.FileTitle) - 4)

    'play midi
    R% = mciSendString("OPEN " + CDBox.filename + " TYPE SEQUENCER ALIAS " + Alias, 0&, 0, 0)
    R% = mciSendString("PLAY " + Alias + " FROM 0", 0&, 0, 0)
    R% = mciSendString("CLOSE ANIMATION", 0&, 0, 0)

    'play midi for 10 secs
    t = Timer
    Do: DoEvents: Loop Until Timer > t + PlayTime

    'stop midi and close it
    R% = mciSendString("OPEN " + CDBox.filename + " TYPE SEQUENCER ALIAS " + Alias, 0&, 0, 0)
    R% = mciSendString&("STOP " + Alias, 0&, 0, 0)
    R% = mciSendString&("CLOSE ANIMATION", 0&, 0, 0)
End Sub

1S4ludo


« Última modificación: 5 Mayo 2007, 20:21 pm por E0N » En línea

CsarGR

Desconectado Desconectado

Mensajes: 47


Ver Perfil
Re: mciSendString
« Respuesta #2 en: 6 Mayo 2007, 11:52 am »

He probado ambas soluciones y ninguna me funciona.
Lo que pretendo es reproducir dos sonidos a la vez, pero estoy viendo que sino hay objetos, con el "mcsendstring" cuando pare uno, pararan los dos.
Es decir, con mcisendstring no podré reproducir dos sonidos wav a la vez, que es lo q quiero.

¿Sabeis qué puedo hacer?

Gracias
En línea

CsarGR

Desconectado Desconectado

Mensajes: 47


Ver Perfil
Re: mciSendString
« Respuesta #3 en: 6 Mayo 2007, 19:29 pm »

¿alguien puede decirme que hago mal?

Cuando utilizo el mcisendstring sp devuelve un numero enorme (y no "0" como deberia ser si fuera bien) y no reproduce nada.
La direccion del sonido .wav esta bien.
Si alguien puede probarlo y decirme qué esta mal se lo agradecería, pq tengo q utilizar el mcisendstring (No puedo utilizar ningun ocx)

Mi codigo es el sg:

Public Class Form1
    Inherits System.Windows.Forms.Form

    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
    Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal uLength As Long) As Long

    Private Direccion As String
    Private cadena As String

    Sub MandarMensaje(ByVal mensaje As String)
        Dim resultado As Long

        cadena = Space(255)
        resultado = mciSendString(mensaje, cadena, Len(cadena), 0)
        BuscarError(resultado)
    End Sub


    Sub BuscarError(ByVal número As Long)
        Dim errorBE As String

        errorBE = Space(255)
        mciGetErrorString(número, errorBE, 255)
        Label1.Text = errorBE
    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim openFileDialog1 As New OpenFileDialog
        openFileDialog1.InitialDirectory = CurDir() & "\Sonidos"
        openFileDialog1.FilterIndex = 1
        openFileDialog1.RestoreDirectory = True

        If openFileDialog1.ShowDialog() = DialogResult.OK Then
            Direccion = openFileDialog1.FileName

            TextBox1.Text = Direccion

            MandarMensaje("close archivowav")
            MandarMensaje("open " & Direccion & " type waveaudio alias archivowav")
            MandarMensaje("set archivowav time format milliseconds")
            MandarMensaje("status archivowav length")
            If Val(Trim(cadena)) <> 0 Then ' Si dicho tiempo es distinto de 0
                ProgressBar1.Minimum = 1
                ProgressBar1.Maximum = Val(cadena)
                ProgressBar1.Value = 1
                Slider1.Minimum = 1
                Slider1.Maximum = Val(cadena)
                Slider1.Value = 1
            End If
            Label2.Text = Format(Val(cadena), "MM:SS")
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Timer1.Enabled = True
        MandarMensaje("play archivowav from 0")
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        MandarMensaje("status archivowav position")
        ProgressBar1.Value = Val(cadena)
        Slider1.Value = Val(cadena)
        Label2.Text = Format(ProgressBar1.Maximum - Val(cadena), "MM:SS")
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        MandarMensaje("stop archivowav")
        Timer1.Enabled = False
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Button4.Text = "Pausa" Then
            MandarMensaje("pause archivowav")
            Button4.Text = "Continuar"
        Else
            MandarMensaje("resume archivowav")
            Button4.Text = "Pausa"
        End If
    End Sub
End Class


Gracias a todos
En línea

CsarGR

Desconectado Desconectado

Mensajes: 47


Ver Perfil
Re: mciSendString
« Respuesta #4 en: 7 Mayo 2007, 12:47 pm »

Así se verá mejor:

No veo donde está el fallo.

Espero que alguien vea donde esta el fallo


Código:
Public Class Form1
    Inherits System.Windows.Forms.Form

    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
    Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal uLength As Long) As Long

    Private Direccion As String
    Private cadena As String

    Sub MandarMensaje(ByVal mensaje As String)
        Dim resultado As Long

        cadena = Space(255)
        resultado = mciSendString(mensaje, cadena, Len(cadena), 0)
        BuscarError(resultado)
    End Sub


    Sub BuscarError(ByVal número As Long)
        Dim errorBE As String

        errorBE = Space(255)
        mciGetErrorString(número, errorBE, 255)
        Label1.Text = errorBE
    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim openFileDialog1 As New OpenFileDialog
        openFileDialog1.InitialDirectory = CurDir() & "\Sonidos"
        openFileDialog1.FilterIndex = 1
        openFileDialog1.RestoreDirectory = True

        If openFileDialog1.ShowDialog() = DialogResult.OK Then
            Direccion = openFileDialog1.FileName

            TextBox1.Text = Direccion

            MandarMensaje("close archivowav")
            MandarMensaje("open " & Direccion & " type waveaudio alias archivowav")
            MandarMensaje("set archivowav time format milliseconds")
            MandarMensaje("status archivowav length")
            If Val(Trim(cadena)) <> 0 Then ' Si dicho tiempo es distinto de 0
                ProgressBar1.Minimum = 1
                ProgressBar1.Maximum = Val(cadena)
                ProgressBar1.Value = 1
                Slider1.Minimum = 1
                Slider1.Maximum = Val(cadena)
                Slider1.Value = 1
            End If
            Label2.Text = Format(Val(cadena), "MM:SS")
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Timer1.Enabled = True
        MandarMensaje("play archivowav from 0")
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        MandarMensaje("status archivowav position")
        ProgressBar1.Value = Val(cadena)
        Slider1.Value = Val(cadena)
        Label2.Text = Format(ProgressBar1.Maximum - Val(cadena), "MM:SS")
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        MandarMensaje("stop archivowav")
        Timer1.Enabled = False
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Button4.Text = "Pausa" Then
            MandarMensaje("pause archivowav")
            Button4.Text = "Continuar"
        Else
            MandarMensaje("resume archivowav")
            Button4.Text = "Pausa"
        End If
    End Sub
End Class
En línea

~~
Ex-Staff
*
Desconectado Desconectado

Mensajes: 2.981


Ver Perfil WWW
Re: mciSendString
« Respuesta #5 en: 7 Mayo 2007, 13:21 pm »

A lo mejor es por la ruta, prueva a obtener la ruta corta por q creo recordar q rutas como C:\archivo de programa o ese tipo de nombres con mas de 8 caracteres no funcionan.
Tienes q obtener el nomre corto con la api GetShortPathName  ;)

Prueva y nos cuentas q tampoco estoy 100% seguro
1S4ludo
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
mciSendString
Programación C/C++
samirllorente 9 4,202 Último mensaje 22 Octubre 2013, 17:45 pm
por Eternal Idol
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines