Results 1 to 5 of 5

Thread: I need a component in Lazarus to play a WAV file.

  1. #1

    I need a component in Lazarus to play a WAV file.

    Hi All,

    I'm porting a Delphi 7 program to Lazarus and I cannot find a TMediaPlayer component. I need a MediaPlayer-like component so that I can play Micro$oft Windows .WAV (sound wave files).

    Below is the code I'm trying to convert to Lazarus:

    Code:
    var
       MediaPlayer1 : TMediaPlayer;
    ....
    procedure TMainForm.play_wave(sound_effect_wave_filename: string);
    
    begin
      if Want_Sound then
      begin
        // note: this 'if' test has deliberately NOT been
        // combined with the above 'if Want_sound' test
        // so that we only check 'if FileExists' when we want sound effects.
        // IOW - don't check FileExists if we don't want sound effects.
        if FileExists(sound_effect_wave_filename) then
        begin
          with MediaPlayer1 do
          begin
            filename := sound_effect_wave_filename;
            AutoRewind := true;
            Open;
            Wait := true;
            Play;
            Close;
          end;
        end;
      end;
    end;
    Any help will be appreciated.

    Yours Sincerely and With Best Wishes,
    pew { Peter_from_Hobart }

    signing off from Hobart, Tasmania, Australia
    (in Winter time here)
    Love, Friendship and Best Wishes<br />Peter the Poet aka PEW

  2. #2

    I need a component in Lazarus to play a WAV file.

    Hi Peter,
    I'm not aware of a built in TMediaPlayer component for Lazarus. I know that if you use SDL via JEDI-SDL you could certainly write one. Actually the JEDI-SDL CVS contains a SDL_Mixer class wrapper that could be used to load and play Wavs and other sound media.

    I hope this helps.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  3. #3

    How can I get the SDL_Mixer program you mentioned.

    Hi Savage,

    Savage wrote:

    > I'm not aware of a built in TMediaPlayer component for Lazarus. I know that if you use SDL via JEDI-SDL you could certainly write one. Actually the JEDI-SDL CVS contains a SDL_Mixer class wrapper that could be used to load and play Wavs and other sound media.

    okay... this project is getting bigger that Ben Hurr!!!

    Can you please tell me the URL for me to get the JEDI-SDL CVS including the SDL_Mixer class wrapper that you mentioned would be able to play the WAV files. Also, I really need example programs showing me how to do it.

    Yours Sincerely,
    pew { peter_from_hobart }

    Hobart, Tasmania, Australia.
    Love, Friendship and Best Wishes<br />Peter the Poet aka PEW

  4. #4

    I need a component in Lazarus to play a WAV file.

    this 'if' test has deliberately NOT been
    // combined with the above 'if Want_sound' test
    AFAIK, the compiler generates such code that it stops evaluating the boolean expression once its result is certain.

    So, the construct

    [pascal]var s: ansistring;
    ...
    if Assigned(s) and (s[1] = 'ы') then .....[/pascal]
    is absolutely safe, since s[1] check is never performed if the string is empty.


    So, [pascal]procedure TMainForm.play_wave(sound_effect_wave_filename: string);
    begin
    if Want_Sound and FileExists(sound_effect_wave_filename)
    then with MediaPlayer1 do
    begin
    filename := sound_effect_wave_filename;
    AutoRewind := true;
    Open;
    Wait := true;
    Play;
    Close;
    end;
    end;[/pascal]

  5. #5

    I need a component in Lazarus to play a WAV file.

    The URL to the audio mixer class is...
    http://jedi-sdl.cvs.sourceforge.net/...r.pas?view=log

    Revision 1.4 is the latest version.

    Within sdlaudiomixer.pas are several classes you can use...
    TSDLSoundEffect - Handles just 1 sound effect
    TSDLSoundEffectManager - Handles x sound effects
    TSDLMusic - Handles just 1 music file
    TSDLMusicManager - Handles x music files
    TSDLAudioManager - Handle collections of both SoundEffects and Music files.

    The SoundEffect and Music classes all support
    Play
    Stop
    Pause
    Resume
    Rewind
    as well as setting the Volume and Fading In and out.
    You can also LoadFromFile. Though LoadFromStream exists as a method, these are not implemented yet.

    A typical way of using TSDLSoundEffect or TSDLMusic on it's own would be ..
    [pascal]var
    MySoundEffect : TSDLSoundEffect;

    begin
    MySoundEffect : TSDLSoundEffect.Create('<path>\MyWavFile.wav');
    MySoundEffect.Play;
    end;[/pascal]

    The Manager classes allows you to add several SoundEffect or Music classes and then refer to them by name or index after they have been added to their respective lists...

    [pascal]MyAudoManager.SoundEffectNames['explosion'].Play;[/pascal]
    or
    [pascal]MyAudoManager.TrackNames['background'].Play;[/pascal]

    Note in order to compile and use this you will also need the other sdl related files that these classes are built from. Namely
    sdl_mixer - http://jedi-sdl.cvs.sourceforge.net/...r.pas?view=log

    sdl - http://jedi-sdl.cvs.sourceforge.net/...l.pas?view=log

    smpeg - http://jedi-sdl.cvs.sourceforge.net/...g.pas?view=log
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •