Topic: Воспроизведение музыкального файла

Как воспроизвести музыкальный файл?

Re: Воспроизведение музыкального файла

Hello karim

I used this fonction for a project made with MVD (old version).
I display photo of a bird and by clicking on a button, I can hear its own song.

1 - When I click on bird picture :(I stop Mediaplayer if ever it's on for another bird)

procedure Affichage_Edit1_OnMouseDown (Sender: string; MouseLeft, MouseRight, MouseMiddle: boolean; Shift, Alt, Ctrl: boolean; X, Y: Integer);
begin
    Affichage.Edit1.Clear;               // Au clic de la souris, on vide le champ
    MediaPlayer.Stop;                    // Arrêt du MediaPlayer
    Affichage.Grille.SelectedRow := 0;   // Le 1er record est mis en surbrillance
    Affichage.DBImage1.LoadFromDatabase('Oiseaux', 'Photo', Affichage.Grille.dbItemID);  //  On affiche la photo du 1er record
    Affichage.Label2.Caption := '';     //  On efface la label contenant le nom de l'oiseau
    Affichage.Label4.Caption := '';     // On efface la label contenant le chemin du chant
end;


2 - With mouse, I choose another bird from the grid :

procedure Affichage_Image5_OnClick (Sender: string);  //Bouton Lecture du Player
var  s: string;
begin
     s := SQLExecute('SELECT chant_filename from oiseaux WHERE id=' + IntToStr(Affichage.Grille.dbItemID) );
     s := ExtractFileDir(Application.ExeName) + s;
     if FileExists(s) then MediaPlayer.PlayFile(s);
end;

I use also functions Stop, Pause for Mediaplayer :
Mediapler.Pause and Mediaplayer.Stop.

First of all, when designing tha databse, I have setup a song for each bird (with property LinkFile to make a folder Songs apart)

Can this be a clue for you ?

No heasitation to ask any help

JB

Re: Воспроизведение музыкального файла

thanks for reply jean.brezhonek.
I have a *.wav file, which is in my local folder of project. I just want it to be played when an even occurs. Your example is when the file is stored in database but mine is in my local folder of project. Can you give me a simple example?

Re: Воспроизведение музыкального файла

thanks I found it.
PlaySound('...\ding.wav');

Re: Воспроизведение музыкального файла

Hello karim

Another way to play a sound :

procedure Form1_OnShow (Sender: TObject; Action: string);
begin
          MediaPlayer.PlayFile('MySound.mp3');
end;


To make your sound file weigh less, turn it into mp3

JB

Re: Воспроизведение музыкального файла

ok. thanks for help.

Re: Воспроизведение музыкального файла

Можно использовать процедуру PlaySound(), в качестве параметра передаётся имя файла. Но при этом файл будет воспроизведён полностью. Решение  jean.brezhonek более универсальное и позволяет управлять воспроизведением.

Визуальное программирование: блог и телеграм-канал.