IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Delphi Discussion :

Détecter la fin d'un fichier wav


Sujet :

Delphi

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    55
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 55
    Points : 63
    Points
    63
    Par défaut Détecter la fin d'un fichier wav
    Salut à tous,



    Je cherche une fonction qui me renvoit en résultat un boolean pour savoir si un fichier wav est entrain d'etre jouer (via l'api playsound). Les tags de l'api playsound (async ou sync) ne collent malheureusement pas. En fait un petit vumetre pour fichier wav collerait tres bien. Donc si vous pouvez m'aiguiller ca serait sympas

    Merci

  2. #2
    Membre expert
    Avatar de LadyWasky
    Femme Profil pro
    Inscrit en
    Juin 2004
    Messages
    2 932
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations forums :
    Inscription : Juin 2004
    Messages : 2 932
    Points : 3 565
    Points
    3 565
    Par défaut
    Salut, en fait, ton problême revient à savoir si ton fichier est déjà ouvert ou non.
    Tu devrais, en ce sens pouvoir

    Si par contre tu cherches à savoir où en est la lecture de ton fichier son, il va falloir que tu passes par les fonctions du genre WaveOutxxxxxxxx et une fonction de Callback comme WaveOutProc au lieu d'utiliser Playsound.

    Mais alors là, je n'ai jamais essayé...

    Ou alors....

    Comme ton fichier wav est en mémoire, tu envoi les données du son petits bouts par petits bouts à sndPlaySound en reconstruisant un mini fichier son comme on le montre dans la FAQ que je t'ai mis sur l'autre post. Par contre, le son risque d'ètre un poil saccadé.
    Bidouilleuse Delphi

  3. #3
    Membre expert
    Avatar de LadyWasky
    Femme Profil pro
    Inscrit en
    Juin 2004
    Messages
    2 932
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations forums :
    Inscription : Juin 2004
    Messages : 2 932
    Points : 3 565
    Points
    3 565
    Par défaut
    Ou alors...

    j'ai trouvé ceci via Google :
    (ça ne devrait pas être trop dur pour adapter ça à un fichier wav)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    unit Unit1;
    {
      This demo shows how to play AVI video from memory using
      the mciSendCommand and mmio functions
     
      Date: 17 Oct 2003
     
      (c) Nils Haeck www.simdesign.nl
     
    }
     
    interface
     
    uses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, MMSystem, ExtCtrls;
     
    type
      TForm1 = class(TForm)
        edFilename: TEdit;
        Label1: TLabel;
        btnPick: TButton;
        btnOpen: TButton;
        btnPlay: TButton;
        lbDeviceID: TLabel;
        Panel1: TPanel;
        procedure btnPickClick(Sender: TObject);
        procedure btnOpenClick(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
        procedure btnPlayClick(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        FIsOpened: boolean;
        FDeviceID: Word;
      public
      end;
     
    var
      Form1: TForm1;
     
    implementation
     
    {$R *.DFM}
     
    // Global memory pointer - for now
    var
      FMem: pointer = nil;
      FSize: integer = 0;
      FOpened: boolean = False;
    const
      FFourCC = 'IOCB'; // acronym for IO CallBack (but it really does not matter - choose as you wish)
     
    function MyIOCallback(lpmmioinfo: PChar; uMessage: UINT; lParam1, lParam2: LPARAM): Longint stdcall;
    // This function is called and will provide access to the file. The MM system "thinks"
    // this is a file, while we use the global memory stream.
    var
      AInfo: pmmioInfo;
    begin
      AInfo := pmmioInfo(lpmmioinfo);
      case uMessage of
      MMIOM_OPEN:
        // Open the "file"
        begin
          if FOpened then begin
            Result := 0;
            exit;
          end;
          FOpened := True;
          AInfo.lDiskOffset := 0;
          Result := 0;
        end;
      MMIOM_CLOSE:
        // Close the "file"
        Result := 0;
      MMIOM_READ:
        // Read data from the "file"
        begin
          // Copy from memory - no checking
          Move(pointer(integer(FMem) + AInfo.lDiskOffset)^, pointer(lParam1)^, lParam2);
          AInfo.lDiskOffset := AInfo.lDiskOffset + lParam2;
          Result := lParam2;
        end;
      MMIOM_SEEK:
        // Seek new position in the "file"
        begin
          case lParam2 of
          // From beginning:
          0: AInfo.lDiskOffset := lParam1;
          // From current:
          1: AInfo.lDiskOffset := AInfo.lDiskOffset + lParam1;
          // From end:
          2: AInfo.lDiskOffset := FSize - 1 - lParam1;
          end;
          Result := AInfo.lDiskOffset;
        end;
      else
        // Unexpected msgs. For instance, we do not process MMIOM_WRITE in this sample
        Result := -1;
      end;
    end;
     
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      // Setup mmio callback
      if not assigned(mmioInstallIOProc(mmioStringToFourCC(FFou  rCC, 0), @MyIOCallback, MMIO_INSTALLPROC or MMIO_GLOBALPROC)) then
        ShowMessage('Could not install IO proc');
    end;
     
    procedure TForm1.FormDestroy(Sender: TObject);
    var
      GenParm: TMCI_Generic_Parms;
    begin
      // Close MCI
      if FIsOpened then begin
        GenParm.dwCallback := Handle;
        mciSendCommand(FDeviceID, mci_Close, 0, Longint(@GenParm));
        FIsOpened := False;
      end;
     
      // remove mmio callback
      mmioInstallIOProc(mmioStringToFourCC(FFourCC, 0), nil, MMIO_REMOVEPROC);
     
      // Free globally assigned memory
      if assigned(FMem) then FreeMem(FMem);
    end;
     
    procedure TForm1.btnPickClick(Sender: TObject);
    begin
      with TOpendialog.Create(nil) do
        try
          Title := 'Open MP3 file';
          Filter := 'Multimedia files|*.mp3;*.avi;*.mpg';
          if Execute then
            edFilename.Text := FileName;
        finally
          Free;
        end;
    end;
     
    procedure TForm1.btnOpenClick(Sender: TObject);
    var
      S: TStream;
      OpenParm: TMCI_Open_Parms;
      GenParm: TMCI_Generic_Parms;
      FFlags: Longint;
      FError: Longint;
      ErrMsg: array[0..4095] of Char;
      AError: string;
    begin
      // Open the file
      S := TFileStream.Create(edFilename.Text, fmOpenRead or fmShareDenyNone);
      try
        if assigned(FMem) then FreeMem(FMem);
     
        if FIsOpened then begin
          GenParm.dwCallback := Handle;
          mciSendCommand(FDeviceID, mci_Close, 0, Longint(@GenParm));
          FIsOpened := False;
        end;
     
        // Copy to global memory
        FSize := S.Size;
        GetMem(FMem, FSize);
        S.Read(FMem^, FSize);
     
      finally
        S.Free;
      end;
     
      // Now try the media player .. see if it wants to play from memory
      FillChar(OpenParm, SizeOf(TMCI_Open_Parms), 0);
     
      // Open a specific device type - obviously, and unfortunately,
      // the memory play function does NOT work for mpegvideo.
      //  OpenParm.lpstrDeviceType := 'mpegvideo'; // does not work
      OpenParm.lpstrDeviceType := 'avivideo';
     
      // Set the name of the file with extension .IOCB+ to invoke our own
      // I/O callbacks. This way the file is read from memory
      OpenParm.lpstrElementName := 'test.IOCB+';
      // OpenParm.lpstrElementName := PChar(edFilename.Text); // alternative, directly read file
      OpenParm.dwCallback := Handle;
     
      FFlags := mci_Open_Type or MCI_OPEN_ELEMENT;
      FError := mciSendCommand(0, mci_Open, FFlags, Longint(@OpenParm));
     
      if FError <> 0 then begin
        // problem opening device
        if not mciGetErrorString(FError, ErrMsg, SizeOf(ErrMsg)) then
          AError := 'Unknown error'
        else
          SetString(AError, ErrMsg, StrLen(ErrMsg));
        lbDeviceID.Caption := AError;
      end else begin
        // device successfully opened
        FIsOpened := True;
        FDeviceID := OpenParm.wDeviceID;
        // Display device ID
        lbDeviceID.Caption := Format('Device ID: %d', [FDeviceID]);
      end;
     
    end;
     
    procedure TForm1.btnPlayClick(Sender: TObject);
    var
      PlayParm: TMCI_Play_Parms;
      AWindowParm: TMCI_Anim_Window_Parms;
      FError: Longint;
    begin
      if not FIsOpened then exit;
      AWindowParm.Wnd := Longint(Panel1.Handle);
      FError := mciSendCommand(FDeviceID, mci_Window, mci_Wait or mci_Anim_Window_hWnd, Longint(@AWindowParm) );
     
      // play
      PlayParm.dwCallback := Handle;
      FError := mciSendCommand(FDeviceID, mci_Play, 0, Longint(@PlayParm));
    end;
     
    end.
    Bidouilleuse Delphi

  4. #4
    Membre émérite Avatar de edam
    Homme Profil pro
    Développeur Delphi/c++/Omnis
    Inscrit en
    Décembre 2003
    Messages
    1 894
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur Delphi/c++/Omnis
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 1 894
    Points : 2 771
    Points
    2 771
    Par défaut
    Citation Envoyé par waskol
    Si par contre tu cherches à savoir où en est la lecture de ton fichier son, il va falloir que tu passes par les fonctions du genre WaveOutxxxxxxxx et une fonction de Callback comme WaveOutProc au lieu d'utiliser Playsound.
    ou simplement telecharge ce merveilleu pakage qui utlise ces fonction cité par waskol:
    http://www.delphiarea.com/products/#Wave_Audio
    PAS DE DESTIN, C'EST CE QUE NOUS FAISONS

  5. #5
    Expert confirmé
    Avatar de Sub0
    Homme Profil pro
    Développeur Web
    Inscrit en
    Décembre 2002
    Messages
    3 573
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Décembre 2002
    Messages : 3 573
    Points : 4 219
    Points
    4 219
    Par défaut
    Salut!

    Dans le cas où tu utilises des samples pas trop volumineux, regarde cette démo avec DirectSound (plus rapide et plus compatible que les fonctions de l'unité MMSystem). Tu n'auras aucun mal à obtenir la taille et la position courante de lecture du sample :

    http://sub0.developpez.com/FormatWAV/mixsound.zip

    Mais surtout, l'avantage est de pouvoir lancer simultanément plusieurs lectures de samples, définir pour chaque sample, la position de départ, le panning (voie de droite et/ou gauche), la fréquence de lecture, etc...
    à+
    De retour parmis vous après 10 ans!!

Discussions similaires

  1. [XL-2007] Détecter la fin de fichier (EOF)
    Par ARTETA13 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 30/03/2012, 12h38
  2. Est-il possible de détecter la modification d'un fichier ?
    Par Kokito dans le forum API, COM et SDKs
    Réponses: 13
    Dernier message: 25/06/2004, 10h42
  3. Réponses: 4
    Dernier message: 22/12/2003, 11h12
  4. Lecture de fichiers ".WAV"...
    Par 0x4e84 dans le forum Langage
    Réponses: 2
    Dernier message: 03/09/2002, 09h43
  5. [Kylix] jouer un fichier wav avec kilyx
    Par JlouisI dans le forum EDI
    Réponses: 1
    Dernier message: 14/06/2002, 02h05

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo