• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

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?
0
Enej
Asked:
Enej
1 Solution
 
IndefreiCommented:
This are 4!!! questions
0
 
IndefreiCommented:
>>Is it possible to have MPlayer detect caption words and play?
Use a timer
0
 
VenneCommented:
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.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
EnejAuthor Commented:
Detailed answer pleae....
0
 
EnejAuthor Commented:
Adjusted points to 60
0
 
IndefreiCommented:
Try this
unit Midiplayer1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    StopButton: TButton;
    ListBox1: TListBox;
    Timer1: TTimer;
    Timer2: TTimer;
    MediaPlayer1: TMediaPlayer;
    Label1: TLabel;
    Button4: TButton;
    procedure FormActivate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure StopButtonClick(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  PlayFlag :Integer;
implementation

{$R *.DFM}

procedure TForm1.FormActivate(Sender: TObject);
begin
   Index :=0;
   PlayFlag :=0;
   RandomInd:=0;
   Timer1.Enabled:=False;
   Mediaplayer1.autoOpen := true;
   mediaplayer1.DeviceType:=dtAutoSelect;
   MediaPlayer1.FileName :=ListBox1.Items.Strings[2];
   mediaplayer1.open;

   Timer2.Enabled:=True;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
    StopButtonClick(Form1);
    Timer2.Interval := 0;
    Timer2.Enabled := False;
end;

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

    case Mediaplayer1.mode of

    mpPlaying :
     begin
        Timer1.Enabled := True;
     end;
    mpStopped :
     begin
        Mediaplayer1.play;
     end;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject); //Play
begin
    StopButtonClick(Form1);
    MediaPlayer1.FileName :=ListBox1.Items.Strings[1];
    mediaplayer1.open;
    Mediaplayer1.play;
end;

procedure TForm1.Button2Click(Sender: TObject); //Looping
begin
     StopButtonClick(form1);
     MediaPlayer1.FileName :=ListBox1.Items.Strings[2];
     mediaplayer1.open;
     Timer1Timer(form1);
end;

procedure TForm1.StopButtonClick(Sender: TObject);
begin
     Timer1.Interval := 0;
     Timer1.Enabled := False;
     Playflag:=0;
     Mediaplayer1.stop;
     Mediaplayer1.Close;
     Mediaplayer1.AutoEnable:=True;
     Mediaplayer1.Autorewind:=True;
     Mediaplayer1.autoOpen := true;
     mediaplayer1.DeviceType:=dtAutoSelect;

end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin
    Timer2.Interval := 100;
    Timer2.Enabled := True;
    If label1.Caption='Good' then
    begin
        If Playflag = 1 then
        begin
             case Mediaplayer1.mode of

             mpPlaying :
              begin
                   Timer1.Enabled := True;
              end;
             mpStopped :
              begin
                   Label1.Caption:='Done';
                   Playflag:=0;
              end;
             end;
        end
        else
        begin
            StopbuttonClick(form1);
            MediaPlayer1.FileName :=ListBox1.Items.Strings[2];
            mediaplayer1.open;
            Mediaplayer1.Play;
            PlayFlag:=1;
        end;
     end;
end;

procedure TForm1.Button4Click(Sender: TObject); //Label=Good
begin
     Label1.Caption:='Good';
end;

procedure TForm1.Button3Click(Sender: TObject); //Random
begin
    StopButtonClick(Form1);
//    Randomize;

    MediaPlayer1.FileName :=ListBox1.Items.Strings[random(ListBox1.Items.Count - 1)];
    mediaplayer1.open;
    Mediaplayer1.play;
end;

end.
Regards
Indi
0
 
IndefreiCommented:
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
0
 
IndefreiCommented:
Ooops
and delete the integers randomInd and Index
0
 
IndefreiCommented:
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

 
 
0
 
EnejAuthor Commented:
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???

0
 
IndefreiCommented:
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

0
 
IndefreiCommented:
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
0
 
EnejAuthor Commented:
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...
0
 
IndefreiCommented:
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
0
 
dur0000Commented:
Hi, thanks for the comments. <a href="http://www.randomind.com">http://www.randomind.com</a>
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now