Link to home
Start Free TrialLog in
Avatar of Enej
Enej

asked on

MediaPlayer

Few questions:
- I would like my application to play
*.mdi files randomely one after another.
(One finishes and another starts).How?
- One and the same *.mdi plays all the time.How?
- I would like my App. to play *.wav
as soon as Label1.Caption 'Good!'
is displayed.Can seem to get it to work
because when i write after Label1...
MediaPlayer1.Play (Autoopen and Active is set to true),it does not seem to work.
Is it possible to have MPlayer detect caption words and play?
Avatar of Indefrei
Indefrei

This are 4!!! questions
>>Is it possible to have MPlayer detect caption words and play?
Use a timer
you want play midi recycle?
put a timer on your form, and examine the mediaplayer.mode, if these value equal mpStopped, then you can rewind midi, and replay it .like these , you can play another midifile.
if you want play a wav when label display, try using sndPlaySound API instead  Mediaplayer.
Avatar of Enej

ASKER

Detailed answer pleae....
Avatar of Enej

ASKER

Adjusted points to 60
ASKER CERTIFIED SOLUTION
Avatar of Indefrei
Indefrei

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ehmmm...
and fill the listBox for this examle with e.g.

C:\Win95\Media\Chord.wav
C:\Win95\Media\Canyon.mid
C:\Win95\Media\Ctmelody.wav
C:\programme\creative\ctsnd\samples\reggae.mid
C:\programme\creative\ctsnd\samples\ballade.mid
cheers
Indi
Ooops
and delete the integers randomInd and Index
O Oh.. again
cause you can't close a not yet opened player, please, not to use it twice make the stopbutton invisible or so...
This is only an example how all can work, perhaps there are  tiny bugs, just figure it out.
good luck
Indi

 
 
Avatar of Enej

ASKER

Actually, what I am trying to do is this:
Have the music play continuously  while my application is running.
All the music files are in a separate folder :(C:\Music)and the application should load /play them randomely in continuous.Eliminating the music is
done by means of a  menu with(checkbox)
(If checked true then music play else
music stop).That is all!
Any help???

First read all files into the listbox
If you don't know how, i tell you
THAT'S ANOTHER QUESTION !!!

and then
put into  procedure TForm1.FormActivate(Sender: TObject);
or better FormCreate
If Musikcheck.State = cbchecked Then
     begin
........load and play randomly WITHIN A TIMER !!!
// you do have all the stuff you need for this ,see up above !
else
stopbuttonclick   //see above
I think you don't wanna let somebody write the whole thing for you
Use your brain, you are a programmer, aren't you !
Indi

Ok, did not realize that you increased the points
this is by M_Adil
 
procedure FindFile(PathFileName : string; IncludeSubDirs : Boolean);
      var
        srec : TSearchRec;
        Path, FileName : String;
      begin
       Path := ExtractFilePath(PathFileName); // give one name
       FileName := ExtractFileName(PathFileName);

       // CurrentDirectory
       if findfirst(PathFileName,faanyfile,srec) = 0 then
       begin
         repeat
           If Not(srec.attr and fadirectory > 0) then
           begin
              if ExtractFileExt((Srec.Name))= myExt then          
              begin
                //Do something, get the name (Srec.Name)
                //inc a counter or add to Listbox1 !!!
              end;
       
           end;
         Until findnext(srec) <> 0;
       end;
       FindClose(SRec);
       { SubDirectories }
       If IncludeSubDirs then
       begin
         if FindFirst(Path+'*.*',FaAnyFile,Srec) = 0 then
         begin
           repeat
             // StartRecursion
             if not(Srec.Name[1] = '.') and (srec.attr and fadirectory > 0)then
               FindFile(Path + Srec.Name + '\' + FileName,IncludeSubDirs)
           Until findnext(srec) <> 0;
         end;
         FindClose(SRec);
       end;

Hope, that you can do it now
regards
Indi
Avatar of Enej

ASKER

First read all files into the listbox
If you don't know how, i tell you
THAT'S ANOTHER QUESTION !!!

///I do not know !
Use your brain, you are a programmer, aren't you !
///Not really,just a beginner trying to learn something...
Well, Enej,
Maybe i have been too rough...
and so i made a mistake, too
Sorry for that
and so i made it for you

unit Musikplayer1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, MPlayer, ExtCtrls;

type
  TForm1 = class(TForm)
    MusikCheck: TCheckBox;
    ListBox1: TListBox;
    Timer1: TTimer;
    MediaPlayer1: TMediaPlayer;
    procedure FormCreate(Sender: TObject);
    procedure FindFile(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure MusikCheckClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private-Deklarationen }

  public
    { Public-Deklarationen }

  end;

var
  Form1: TForm1;
  myExt : string;
  PathFileName,Path, FileName : String;
implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
    PathFileName :='C:\win95\media\*.*';
    MyExt:='.wav'; // whatever
    FindFile(Form1);
    MyExt:='.mid';  // whatever
    FindFile(Form1);
    Mediaplayer1.autoOpen := true;
    mediaplayer1.DeviceType:=dtAutoSelect;
    MediaPlayer1.FileName :=Path + ListBox1.Items.Strings[random(ListBox1.Items.Count - 1)];
    mediaplayer1.open;
    MusikCheckClick(form1);

end;

procedure TForm1.FindFile(Sender: TObject);
var
        srec : TSearchRec;
begin
       Path := ExtractFilePath(PathFileName);
       FileName := ExtractFileName(PathFileName);

       if findfirst(PathFileName,faanyfile,srec) = 0 then
       begin
         repeat
           If Not(srec.attr and fadirectory > 0) then
           begin
              if ExtractFileExt((Srec.Name))= myExt then
              begin
                    ListBox1.Items.Add(Srec.Name);
              end;

           end;
         Until findnext(srec) <> 0;
       end;
       FindClose(SRec);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
    Timer1.Interval := 100;
    Timer1.Enabled := True;

    case Mediaplayer1.mode of

    mpPlaying :
     begin
        Timer1.Enabled := True;
     end;
    mpStopped :
     begin
        Mediaplayer1.Close;
        MediaPlayer1.FileName :=Path + ListBox1.Items.Strings[random(ListBox1.Items.Count - 1)];
        Mediaplayer1.open;
        Mediaplayer1.play;
     end;
    end;
end;

procedure TForm1.MusikCheckClick(Sender: TObject);
begin
     If MusikCheck.State = cbchecked Then
     begin
          Timer1Timer(form1);
     end
     else
     begin
          Timer1.enabled:=false;
          mediaplayer1.Stop;
     end;    
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
    Timer1.enabled:=false;
    mediaplayer1.Stop;
    Mediaplayer1.Close;
end;

end.

Hope this helps now
keep on learning, so do i
CIAO
Indi
Hi, thanks for the comments. <a href="http://www.randomind.com">http://www.randomind.com</a>