Visualizzazione dei risultati da 1 a 10 su 10
  1. #1

    [VB6] Come si costruisce un CD Player?

    Mi sono messo in testa di realizzare un cdplayer tutto mio col VB.
    Onde evitare inutili ocx da trascinarsi dietro, ritengo sia più opportuno usare le API di windows.
    Se non sbaglio esiste una API, mciSendString , che consente di interagire con un device mci.

    Io non sono molto bravo, dunque mi sono scaricato un esempio dalla Microsoft per capire come funziona questa API, ma come sempre succede, l'esempio ha qualcosa che non soddisfa l'utente (cioè io).

    1) intanto ci sono un sacco di comandi ma non ci sono le relative spiegazioni! io conosco VB ma non posso sapere tutto anche delle API! mi servirebbe dunque una lista dei comandi che la mciSendString accetta e sapere anche a cosa servono esattamente.

    2) io ho un CD ed un Masterizzatore SCSI che per esigenze Hardware devono essere messi su di un particolare ID del controller, vale a dire in sostanza che il masterizzatore (ID = 3) è letto con priorità maggiore del CDRom (ID = 4). Ciò provoca uno spiacevole effetto: l'esempio di cui sopra funziona solo se il CD Audio si trova nel masterizzatore...

    Io suppongo che tra i 1000 comandi che la API supporta ce ne sia uno che gli spiega quale lettera deve andare a leggersi (nel caso mio F:\)

    Aspetto suggerimenti, note e insulti.

    Nel caso ci sia bisogno di inviare materiale, mandate tutto qui.



    GRAZIE
    Dice il saggio:
    Non ci sono domande difficili, esistono solo risposte che non conosciamo!
    "Se qualcosa può andare male, lo farà" - Murphy

  2. #2
    Utente di HTML.it L'avatar di garlick
    Registrato dal
    Dec 2001
    Messaggi
    385
    Ciao, anche io ho avuto il tuo stesso problema. Secondo me, la cosa migliore che puoi fare per imparare bene a costruire un cd player è scaricartene uno già fatto; ti consiglio www.planetsourcecode.com/vb.
    Troverai un sacco di esempi pratici, che alla fine sono la cosa migliore. Se poi hai ancora qualche dubbio, chiedi pure, nei limiti della mia conoscenza cercerò di aiutarti. Ciao

  3. #3
    codice:
    'Creare un Modulo .BAS
    Option Explicit
    Private Declare Function GetPrivateProfileString Lib "Kernel32" Alias  _
        "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
        ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString _
        As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
    Private Declare Function WritePrivateProfileString Lib "Kernel32" Alias _
        "WritePrivateProfileStringA" (ByVal AppName As String, ByVal KeyName _
        As String, ByVal keydefault As String, ByVal Filename As String) As Long
    Global CDMin As Integer
    Global CDSec As Integer
    Global TMin As Integer
    Global TSec As Integer
    Global RMin As Integer
    Global RSec As Integer
    Global TimeTrack As String
    Global TimeElapsed As String
    Global TimeRemaining As String
    Global Artist1 As String
    Global Title1 As String
    Global Artist2 As String
    Global Title2 As String
    Sub CDAudioProperties()
        Dim T As Double
        On Error Resume Next
        T = Shell("rundll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,3", 5)
    End Sub
    
    Function GetRawRemainingTime(MMCOntrol1 As Object) As String
        Dim Z As String, Min As String, Sec As String, _
            Temp As String
        Z = GetRunningTime(MMCOntrol1)
        Z = GetTrackTime(MMCOntrol1)
        Min = LTrim$(Str$(CDMin - TMin))
        Sec = LTrim$(Str$(CDSec - TSec))
        RMin = Val(Min)
        RSec = Val(Sec)
        If RSec < 0 Then
            RSec = 60 + Val(Sec)
            RMin = RMin - 1
        End If
        Min = LTrim$(Str$(RMin))
        Temp = Trim$(Str$(RSec))
        If Len(Temp) = 1 Then
            Sec = "0" + Temp
        Else
            Sec = Temp
        End If
        GetRawRemainingTime = Min + Sec
    End Function
    
    Function GetRemainingTime(MMCOntrol1 As Object) As String
        Dim Z As String, Min As String, Sec As String, _
            Temp As String
        Z = GetRunningTime(MMCOntrol1)
        Z = GetTrackTime(MMCOntrol1)
        Min = LTrim$(Str$(CDMin - TMin))
        Sec = LTrim$(Str$(CDSec - TSec))
        RMin = Val(Min)
        RSec = Val(Sec)
        If RSec < 0 Then
            RSec = 60 + Val(Sec)
            RMin = RMin - 1
        End If
        Min = LTrim$(Str$(RMin))
        Temp = Trim$(Str$(RSec))
        If Len(Temp) = 1 Then
            Sec = "0" + Temp
        Else
            Sec = Temp
        End If
        GetRemainingTime = Min + ":" + Sec
    End Function
    
    Sub GetTime(MMCOntrol1 As Object)
        Dim Z$
        Z$ = GetRemainingTime(MMCOntrol1)
    End Sub
    
    Function GetTrackTime(MMCOntrol1 As Object) As String
        Dim Length&, Entry2$, Min$, Sec$, D$, Entry$
        MMCOntrol1.TimeFormat = 2
        Length& = MMCOntrol1.TrackLength
        Min$ = Str$(Length& And &HFF)
        Sec$ = LTrim$(Str$((Length& And 65280) / 256))
        Entry2$ = Min$ & ":" & Sec$
        If Len(Sec$) = 1 Then Entry2$ = Min$ + ":0" + Sec$
        Entry$ = Min$ + ":" + Sec$
        If Len(Entry2$) = 4 Then
            D$ = "0" + Entry2$
        Else
            D$ = Entry2$
        End If
        If Len(Entry2$) = 3 Then
            D$ = "00" + Entry2$
        Else
            D$ = Entry2$
        End If
        D$ = Entry2$
        GetTrackTime = Trim$(D$)
        MMCOntrol1.TimeFormat = 10
        CDMin = Val(Min$)
        CDSec = Val(Sec$)
    End Function
    
    Function GetRunningTime(MMCOntrol1 As Object) As String
        Dim E As Long, M As String, S As String, Length&, Min$, Sec$, D As Long, Entry2$
        MMCOntrol1.TimeFormat = 2
        Length& = MMCOntrol1.Position - MMCOntrol1.TrackPosition
        Min$ = Str$(Length& And &HFF)
        Sec$ = LTrim$(Str$((Length& And 65280) / 256))
        If Len(Sec$) = 3 Then
            D = Val(Min$) - 1
            Min$ = LTrim$(Str$(D))
            E = Val(Right$(Sec$, 2)) + 4
            
            Sec$ = LTrim$(Str$(E))
        End If
        M = Min$
        'If Len(Min$) = 1 Then M = "0" + Min$ Else M = Min$
        'If Val(M) = 0 Then M = "00"
        'If Val(M) = 1 Then M = "01"
        'If Val(M) = 2 Then M = "02"
        'If Val(M) = 3 Then M = "03"
        'If Val(M) = 4 Then M = "04"
        'If Val(M) = 5 Then M = "05"
        'If Val(M) = 6 Then M = "06"
        'If Val(M) = 7 Then M = "07"
        'If Val(M) = 8 Then M = "08"
        'If Val(M) = 9 Then M = "09"
        If Len(Sec$) = 1 Then
            S = "0" + Sec$
        Else
            If Len(Sec$) = 3 Then
                S = Mid$(Sec$, 2)
            Else
                S = Sec$
            End If
        End If
        TMin = Val(M)
        TSec = Val(S)
        Entry2$ = LTrim$(M) + ":" + LTrim$(S)
        MMCOntrol1.TimeFormat = 10
        GetRunningTime = Entry2$
    End Function
    
    Function GetRawRunningTime(MMCOntrol1 As Object) As String
        Dim E As Long, M As String, S As String, Length&, Min$, Sec$, D As Long, Entry2$
        MMCOntrol1.TimeFormat = 2
        Length& = MMCOntrol1.Position - MMCOntrol1.TrackPosition
        Min$ = Str$(Length& And &HFF)
        Sec$ = LTrim$(Str$((Length& And 65280) / 256))
        If Len(Sec$) = 3 Then
            D = Val(Min$) - 1
            Min$ = LTrim$(Str$(D))
            E = Val(Right$(Sec$, 2)) + 4
            
            Sec$ = LTrim$(Str$(E))
        End If
        M = Min$
        'If Len(Min$) = 1 Then M = "0" + Min$ Else M = Min$
        'If Val(M) = 0 Then M = "0"
        'If Val(M) = 1 Then M = "1"
        'If Val(M) = 2 Then M = "2"
        'If Val(M) = 3 Then M = "3"
        'If Val(M) = 4 Then M = "4"
        'If Val(M) = 5 Then M = "5"
        'If Val(M) = 6 Then M = "6"
        'If Val(M) = 7 Then M = "7"
        'If Val(M) = 8 Then M = "8"
        'If Val(M) = 9 Then M = "9"
        If Len(Sec$) = 1 Then
            S = "0" + Sec$
        Else
            If Len(Sec$) = 3 Then
                S = Mid$(Sec$, 2)
            Else
                S = Sec$
            End If
        End If
        Entry2$ = M + S
        MMCOntrol1.TimeFormat = 10
        GetRawRunningTime = Entry2$
    End Function
    
    Function GetRawTrackTime(MMCOntrol1 As Object) As String
        Dim Length&, Entry2$, Min$, Sec$, D$
        MMCOntrol1.TimeFormat = 2
        Length& = MMCOntrol1.TrackLength
        Min$ = Str$(Length& And &HFF)
        Sec$ = LTrim$(Str$((Length& And 65280) / 256))
        Entry2$ = Min$ + Sec$
        If Len(Sec$) = 1 Then Entry2$ = Min$ + "0" + Sec$
        GetRawTrackTime = Entry2$
        MMCOntrol1.TimeFormat = 10
    End Function
    
    Public Function myReadINI(inifile, inisection, inikey, iniDefault)
        'Fail fracefully if no file / wrong file is specified.
        'If no section (appname), default is first appname
        'if no key, default is first key
        Dim lpApplicationName As String
        Dim lpKeyName As String
        Dim lpDefault As String
        Dim lpReturnedString As String
        Dim nSize As Long
        Dim lpFileName As String
        Dim retval As Long
        Dim Filename As String
        lpDefault = Space$(254)
        lpDefault = iniDefault
        lpReturnedString = Space$(254)
        nSize = 254
        lpFileName = inifile
        lpApplicationName = inisection
        lpKeyName = inikey
        Filename = lpFileName
        retval = GetPrivateProfileString _
            (lpApplicationName, lpKeyName, lpDefault, lpReturnedString, nSize, lpFileName)
        myReadINI = lpReturnedString
    End Function
    
    Public Function myWriteINI(inifile As String, inisection As String, inikey _
            As String, Info As String) As String
        Dim retval As Long
        retval = WritePrivateProfileString(inisection, inikey, Info, inifile)
        myWriteINI = LTrim$(Str$(retval))
    End Function
    
    Public Function GenCDSerial(MMCOntrol1 As Object) As Long
        Const MCI_FORMAT_MILLISECONDS = 0
        Const MCI_FORMAT_MSF = 2
        Const MCI_FORMAT_TMSF = 10
        'MCI_Format :0,2,10 are the only supported formats for CD
        Dim Compat As Integer
        Dim i As Integer
        Dim dwtotal&, dwtemp&
        Dim byte0%, byte1%, byte2%, byte3%
        'compat = 0 for EXISTING code
        'Compat = 1 for use with CDPLAYER.EXE
        Compat = 1
        MMCOntrol1.Notify = False
        MMCOntrol1.Wait = True
        MMCOntrol1.Shareable = True
        If MMCOntrol1.Error <> 0 Then
            MsgBox MMCOntrol1.ErrorMessage
            Exit Function
        End If
        MMCOntrol1.TimeFormat = MCI_FORMAT_MSF
        dwtotal& = 0
        For i = 1 To MMCOntrol1.Tracks
            DoEvents
            MMCOntrol1.Track = i
            dwtemp& = MMCOntrol1.TrackPosition
            byte0% = dwtemp& And &HFF&
            byte1% = (dwtemp& And &HFF00&) \ &H100
            byte2% = (dwtemp& And &HFF0000) \ &H10000
            byte3% = (dwtemp& And &H7F000000) \ &H1000000
            If (dwtemp& And &H80000000) <> 0 Then
                ' put sign bit back into byte4
                byte3 = byte3 + &H80
            End If
            dwtemp& = byte0% * &H10000 + byte1% * &H100 + byte2%
            dwtotal& = dwtotal& + dwtemp&
        Next i
        If MMCOntrol1.Tracks < 3 Then
            dwtotal& = dwtotal& + msf2frames(MMCOntrol1.Length) + Compat
        End If
        GenCDSerial = dwtotal&
    End Function
    
    Function msf2frames(msf As Long) As Long
        Rem From the KnowledgeBase
        Rem    byte1 = MMControl1.Position And &HFF&
        Rem    byte2 = (MMControl1.Position And &HFF00&) \ &H100
        Rem    byte3 = (MMControl1.Position And &HFF0000) \ &H10000
        Rem    byte4 = (MMControl1.Position And &H7F000000) \ &H1000000
        Rem    If (MMControl1.Position And &H80000000) <> 0 Then
        Rem       ' put sign bit back into byte4
        Rem       byte4 = byte4 + &H80
        Rem    End If
        Dim byte0, byte1, byte2, byte3 As Integer
        Dim Min, Sec, fra As Integer
        byte0 = msf And &HFF&
        byte1 = (msf And &HFF00&) \ &H100
        byte2 = (msf And &HFF0000) \ &H10000
        byte3 = (msf And &H7F000000) \ &H1000000
        If (msf And &H80000000) <> 0 Then
            ' put sign bit back into byte4
            byte3 = byte3 + &H80
        End If
        Min = byte0
        Sec = byte1
        fra = byte2
        msf2frames = (Min * 60 + Sec) * 75 + fra
        
    End Function
    
    Function Z_Trim(String1 As String) As String
        Dim A As Integer
        For A = 1 To Len(String1)
            If Mid$(String1, A, 1) = Chr$(0) Then Exit For
        Next A
        Z_Trim = RTrim$(Left$(String1, A - 1))
    End Function
    Vascello fantasma dei mentecatti nonchè baronetto della scara corona alcolica, piccolo spuccello di pezza dislessico e ubriaco- Colui che ha modificato l'orribile scritta - Gran Evacuatore Mentecatto - Tristo Mietitore Mentecatto chi usa uTonter danneggia anche te

  4. #4
    Grazie a tutti e due, ma nessuno mi ha ancora detto niente sul problema dell'identificazione del driver giusto per il cd?

    Ne sapete niente?
    Io non posso lavorare sempre sul masterizzatore, anche perché non ho alcuna intensione di metterci il cavetto audio!
    Dice il saggio:
    Non ci sono domande difficili, esistono solo risposte che non conosciamo!
    "Se qualcosa può andare male, lo farà" - Murphy

  5. #5
    Utente di HTML.it L'avatar di garlick
    Registrato dal
    Dec 2001
    Messaggi
    385
    codice:
    Function OpenCD(CD_Drive As String) As Boolean
    Dim ReturnString As String * 30
    CloseCD
    CD_Drive = Mid$(CD_Drive, 1, 1) + ":\"
    OpenCD = Not CBool(mciSendString("open " + CD_Drive + " Type cdaudio alias cdr wait shareable", ReturnString, Len(ReturnString), 0))
    If OpenCD Then mciOpen = True Else mciOpen = False
    mciSendString "set cdr time format tmsf wait", vbNullString, 0, 0
    End Function
    Guarda se così funziona, devi passare a questa funzione una stringa contenente la lettera del driver (e.s. "D:\")

    Fammi sapere, ciao

  6. #6
    se funziona ti faccio un monumento!
    Dice il saggio:
    Non ci sono domande difficili, esistono solo risposte che non conosciamo!
    "Se qualcosa può andare male, lo farà" - Murphy

  7. #7
    Utente di HTML.it L'avatar di garlick
    Registrato dal
    Dec 2001
    Messaggi
    385
    Originariamente inviato da cleverboy
    se funziona ti faccio un monumento!
    Addirittura

    Mica lo ho inventato io :gren:

  8. #8
    Beh, non lo hai inventato te, ma se non era per te io stavo ancora a strapparmi i capelli davanti a sto c...o di player!

    Ahm dimenticato. FUNZIONA!!!
    :metallica

    Sei un genio. Poi magari mi spieghi come facevi a saperlo... voglio dire... hai qualche manuale in merito o è stata una tua intuizione.

    Io cerca e ricerca sul web non ho mai trovato un articolo decente che spiegasse sta API così utile!

    Grazie :sexpulp:
    Dice il saggio:
    Non ci sono domande difficili, esistono solo risposte che non conosciamo!
    "Se qualcosa può andare male, lo farà" - Murphy

  9. #9
    Utente di HTML.it L'avatar di garlick
    Registrato dal
    Dec 2001
    Messaggi
    385
    No, nessun manuale o intuizione o colpo di genio, ho solo adattato e copiato

    Purtroppo è vero, l'argomento delle Api è talmente vasto che è difficilissimo trovare un articolo che te ne spieghi il funzionamento in modo chiaro, per quello ti dicevo che la via migliore sono gli esempi pratici. Io ti ho solo postato un pezzo di codice, ma se vuoi ti invio via email un modulo con delle interessanti funzioni Mci che ti aiuteranno meglio a capirne il funzionamento, o almeno, a me sono servite

  10. #10
    ti ringrazio, mi farebbe comodo!

    mandamelo qui
    Dice il saggio:
    Non ci sono domande difficili, esistono solo risposte che non conosciamo!
    "Se qualcosa può andare male, lo farà" - Murphy

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.