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

Lazarus Pascal Discussion :

[Linux] Jouer du son


Sujet :

Lazarus Pascal

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    52
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 52
    Par défaut [Linux] Jouer du son
    Bonjour,

    Avec Lazarus sous Linux (Ubuntu), comment simplement jouer du son (Wav par exemple)? Sous Delphi (Windows évidemment !) j'utilisais sans problème le composant MPlayer mais je ne vois rien qui le remplace. J'ai fouillé longtemps sur le Web, mais je n'ai rien obtenu d'utilisable. Il y a plein de réponses (en anglais) mais je suis toujours en panne (par exemple on me dit de télécharger MadiaPlayer2, ce que j'ai fait et alors ???). Le problème est sûrement du même ordre pour la video, mais n'en demandons pas trop pour l'instant...

    Merci de vos réponses.

  2. #2
    Membre confirmé

    Homme Profil pro
    retraité
    Inscrit en
    Septembre 2006
    Messages
    65
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : retraité
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Septembre 2006
    Messages : 65

  3. #3
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 596
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 596
    Billets dans le blog
    65
    Par défaut
    Il y a déjà un certain temps , j'avais fait un composant pour cela . A ma grande honte le code n'est pas totalement documenté . Mais surtout il est tombé aux oubliettes (j'ai un peu laissé de coté Lazarus) . Un truc que par contre je n'ai jamais réussi c'est faire des Beeps avec le HP interne (du moins sur ma machine)

    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
    { Unit lzcsound
      Copyright (C) 2009 Lazarus-fr Team
     
      This source is free software; you can redistribute it and/or modify it under
      the terms of the GNU General Public License as published by the Free
      Software Foundation; either version 2 of the License, or (at your option)
      any later version.
     
      This code is distributed in the hope that it will be useful, but WITHOUT ANY
      WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
      details.
     
      A copy of the GNU General Public License is available on the World Wide Web
      at <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing
      to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
      MA 02111-1307, USA.
     
      Author: Serge Girard
     
      Abstract:
        Two components to play wav files 
     
      Requirements: FPC 2.2.4
    }
    unit lzcsound;
     
    {$mode objfpc}{$H+}
     
    interface
     
    uses
      Classes, SysUtils,PropEdits, Dialogs, FileUtil, LResources,LZCBase;
     
    type
     
      TSoundFileNamePropertyEditor = class(TFileNamePropertyEditor)
      public
        function GetDialogTitle : string; override;
        function GetFilter: string; override;
        function GetInitialDirectory: string; override;
        procedure Edit; override;
      end;
     
      TLZCWave = class(TLZCustomComponent)
      protected
        FSoundFile : String;
        FOnPlay    : TNotifyEvent;
      private
        procedure SetSoundFile(const AValue: string);
      public
        procedure Play;
      published
        property  OnPlay  : TNotifyEvent read FOnPlay write FOnPlay;
        property  SoundFile : String read FSoundFile write SetSoundFile;
      end;
     
      TLZClrsWave = class(TLZCustomComponent)
      protected
        FLrsSoundName : String;
        FVolatile : Boolean;
        FOnPlay   : TNotifyEvent;
      public
        procedure Play;
      published
        property  OnPlay  : TNotifyEvent read FOnPlay write FOnPlay;
        property  LrsSoundName : String read FLrsSoundName write FLrsSoundName;
        property  Volatile : Boolean read FVolatile write FVolatile;
      end;
    {$IFDEF WINDOWS}
      SoundFlags =(
            SND_SYNC = $0000,         // play synchronously (default) */
            SND_ASYNC = $0001,        // play asynchronously */
            SND_NODEFAULT = $0002,    // silence (!default) if sound not found */
            SND_MEMORY = $0004,       // pszSound points to a memory file */
            SND_LOOP = $0008,         // loop the sound until next sndPlaySound */
            SND_NOSTOP = $0010,       // don't stop any currently playing sound */
            SND_NOWAIT = $00002000,   // don't wait if the driver is busy */
            SND_ALIAS = $00010000,    // name is a registry alias */
            SND_ALIAS_ID = $00110000, // alias is a predefined ID */
            SND_FILENAME = $00020000, // name is file name */
            SND_RESOURCE = $00040004  // name is resource name or atom */
        );
    {$ENDIF}
    {$IFDEF WINCE}
      function WinCEPlaySound(x1: PWideChar; x2: HMODULE; x3: DWORD): longbool;stdcall; external 'coredll.dll' name 'PlaySoundW';
    {$ENDIF}
    {$IFDEF MSWINDOWS}
      function WindowsPlaySound(pszSound: PChar; hmod: HMODULE; fdwSound: DWORD): BOOLean; stdcall; external 'winmm.DLL' name 'PlaySound';
    {$ENDIF}
     
    procedure Register;
     
    resourcestring
      rsDialogTitle = 'A la recherche du Son Perdu';
      rsDialogFilter = 'Fichiers WAV|*.wav';
     
     
    implementation
     
    uses LazIDEIntf;
     
    procedure Register;
    begin
      RegisterComponents('LZSound',[TLZCWave,TLZClrsWave]);
      RegisterPropertyEditor(TypeInfo(string), TLZCWave, 'SoundFile',TSoundFileNamePropertyEditor);
    end;
     
    {TLZCWave}
    procedure TLZCWave.Play;
    begin
    if Assigned(FOnPlay) then OnPlay(self);
    {$IFDEF WINDOWS}
     {$IFDEF WINCE}
      WinCEPlaysound(FSoundFile,0,0);
     {$ELSE}
      WindowsPlaysound(@FSoundFile[1],0, LongWord(SND_FILENAME));
     {$ENDIF}
    {$ENDIF}
    {$IFDEF LINUX}
     SysUtils.ExecuteProcess(FindDefaultExecutablePath('paplay'),FSoundFile);
    {$ENDIF}
    end;
     
    procedure TLZCWave.SetSoundFile(const AValue: string);
    var
      fn: string;
    begin
      if (FSoundFile = AValue) then
        exit;
      FSoundFile := AValue;
      if (FSoundFile = '') then
        exit;
      if (csDesigning in ComponentState) then
      begin
        fn := ExtractFileName(AValue);
        FSoundFile := ExtractFilePath(AValue);
        FSoundFile := FSoundFile + fn;
      end
      else
      begin
        FSoundFile := AValue;
      end;
    end;
     
    {TLZClrsWave}
     
    procedure TLZClrsWave.Play;
    var FileName : String;
      Stream: TFileStream;
    begin
    FileName:=SysUtils.GetTempDir(False)+FLrsSoundName+'.wav';
    Stream := TFileStream.Create(FileName, fmCreate);
    with LazarusResources.Find(FLrsSoundName) do
        Stream.Write(PChar(Value)^, Length(Value));
    Stream.Free;
    if Assigned(FOnPlay) then OnPlay(self);
    {$IFDEF WINDOWS}
    {$IFDEF WINCE}
      WinCEPlaysound(FileName,0,0);
      {$ELSE}
      WindowsPlaysound(@FileName[1],0, $00020000);
      {$ENDIF}
    {$ENDIF}
    {$IFDEF LINUX}
     SysUtils.ExecuteProcess(FindDefaultExecutablePath('paplay'),FileName);
    {$ENDIF}
    if FVolatile then DeleteFile(FileName);
    end;
     
     
    { TSoundFileNamePropertyEditor }
     
    function TSoundFileNamePropertyEditor.GetFilter: string;
    begin
      Result := rsDialogFilter;
    end;
     
    function TSoundFileNamePropertyEditor.GetDialogTitle: string;
    begin
      Result := rsDialogTitle;
    end;
     
    function TSoundFileNamePropertyEditor.GetInitialDirectory: string;
    begin
      Result := ExtractFilePath(LazarusIDE.ActiveProject.ProjectInfoFile);
    end;
     
    procedure TSoundFileNamePropertyEditor.Edit;
    begin
      With CreateFileDialog do
        Try
          Filter:=rsDialogFilter;
          Options:=GetDialogOptions;
          FileName:=GetStrValue;
          InitialDir:=GetInitialDirectory;
          Title:=GetDialogTitle;
          If Execute then
            SetFilename(Filename);
        Finally
          Free;
        end;
    end;
     
     
    end.

  4. #4
    Expert confirmé
    Avatar de Jipété
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    11 132
    Détails du profil
    Informations personnelles :
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 11 132
    Par défaut
    Bonjour,

    Serge, j'ai parcouru ton code vite fait, et suis tombé en arrêt sur cette ligne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SysUtils.ExecuteProcess(FindDefaultExecutablePath('paplay'),FSoundFile);
    Ça suppose que PulseAudio est installé, correct ?

    Comment ça se passe si ce n'est pas le cas ?
    (J'avoue que le son sous Linux me dépasse un peu, pour le moment...)

  5. #5
    Modérateur
    Avatar de tourlourou
    Homme Profil pro
    Biologiste ; Progr(amateur)
    Inscrit en
    Mars 2005
    Messages
    3 931
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Biologiste ; Progr(amateur)

    Informations forums :
    Inscription : Mars 2005
    Messages : 3 931
    Billets dans le blog
    6
    Par défaut
    Pourquoi ne pas utiliser les bibliothèques Bass ou FMod ?
    Delphi 5 Pro - Delphi 11.3 Alexandria Community Edition - CodeTyphon 6.90 sous Windows 10 ; CT 6.40 sous Ubuntu 18.04 (VM)
    . Ignorer la FAQ Delphi et les Cours et Tutoriels Delphi nuit gravement à notre code !

  6. #6
    Membre confirmé

    Homme Profil pro
    retraité
    Inscrit en
    Septembre 2006
    Messages
    65
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : retraité
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Septembre 2006
    Messages : 65
    Par défaut
    Citation Envoyé par tourlourou Voir le message
    Pourquoi ne pas utiliser les bibliothèques Bass ou FMod ?
    sous linux(ubuntu) ??

  7. #7
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 596
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 596
    Billets dans le blog
    65
    Par défaut
    Citation Envoyé par Jipété Voir le message
    Bonjour,

    Serge, j'ai parcouru ton code vite fait, et suis tombé en arrêt sur cette ligne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SysUtils.ExecuteProcess(FindDefaultExecutablePath('paplay'),FSoundFile);
    Ça suppose que PulseAudio est installé, correct ?

    Comment ça se passe si ce n'est pas le cas ?
    (J'avoue que le son sous Linux me dépasse un peu, pour le moment...)
    comme déjà dit , c'est un code vieux de 3 ans je crois , je ne sais donc plus exactement la démarche que j'ai suivi ()

Discussions similaires

  1. [Linux Ubuntu] Jouer du son
    Par microb dans le forum Contribuez
    Réponses: 7
    Dernier message: 03/04/2011, 20h44
  2. Jouer un son audio C ou C++ ss linux
    Par e_gaillard37 dans le forum Linux
    Réponses: 2
    Dernier message: 19/05/2009, 12h43
  3. Jouer un son audio C ou C++ ss linux
    Par e_gaillard37 dans le forum Applications et environnements graphiques
    Réponses: 1
    Dernier message: 02/05/2009, 08h55
  4. Jouer un son en C++ sous Linux
    Par Padreweak dans le forum C++
    Réponses: 2
    Dernier message: 26/11/2007, 21h33
  5. Réponses: 5
    Dernier message: 21/07/2007, 12h12

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