?
Solved

Mediaplayer1.Play; how to loop?

Posted on 1997-12-25
9
Medium Priority
?
348 Views
Last Modified: 2012-05-04
hi,

I need it so that mediaplayer loops the file it is playing indefinite.
anyone have an idea.
thanks
0
Comment
Question by:hellfire052497
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 3

Accepted Solution

by:
Matvey earned 300 total points
ID: 1354598
It's very easy :

You set the MediaPlaey's Notify property to TRUE (not available in design time), and everytime it stops playing the file the OnNotify event occures - so you can play your file over and over again.

Good luck!
0
 

Author Comment

by:hellfire052497
ID: 1354599
how?

tried

Mediaplayer1.Notify := true;
Mediaplayer1.play;

nothing happened, stopped at one play?

0
 
LVL 4

Expert Comment

by:StevenB
ID: 1354600
 I do this:
 
  Hide the mediaplayer component (and its hideous interface) and put your own set of buttons on the form (there it looks nicer already I expect).
  Set up a boolean called perhaps 'LastClickWasPlay'. Make sure that this boolean is True after a click on the Play Button, but False after any other interaction (because the mediaplayer hurls loads of OnNotify events at you).
  Link all your buttons to the media player methods for play, stop etc.
  Create an event handler for the OnNotify event and put something like this in it:

  MediaPlayer1.Notify := True;
  If LastClickWasPlay then begin
    MediaPlayer1.Play;
    StopButtonClick(self);
  end;

  Basically what Matvey said. You'll probably notice that there is still a brief pause between end and replay of the file. I can't get rid of that, (to my annoyance).

  Good Luck, Steven.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 4

Expert Comment

by:StevenB
ID: 1354601
 Ignore the bit that says:

StopButtonClick(self);

  it crept in somehow during the paste from my code. It has nothing to do with my comment at all.

  Steven.
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1354602
Here is the only code you need, I checked it with .wav and .avi, and it worked...

procedure TForm1.FormCreate(Sender: TObject);
begin
MediaPlayer1.Notify := true;
end;

procedure TForm1.MediaPlayer1Notify(Sender: TObject);
begin
if mediaplayer1.Mode = mpStopped then mediaPlayer1.Play;
end;

I use D3, but this has nothing to do with it, I think.
What kind of files do you play?
Could you send the whole code that makes problems?

By the way, Happy new year!
Matvey
0
 
LVL 4

Expert Comment

by:StevenB
ID: 1354603
 I've not checked it, but will that not make the file replay when, for example, the stop button is pressed? Doesn't the stop button send a notify event which will trigger the event handler you've set up?
  Happy New Year.

  Steven.
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1354604
Yes, I think it will. So if hellfire wants that mpl to be visible he shell use what you sugested.

Thanks for the hint,
Matvey
0
 

Author Comment

by:hellfire052497
ID: 1354605
Confusing to say the least.

As asked I provide my code here, haven't had time to try the last suggestions

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  TransBtn, ExtCtrls, EnhImage, oxForm, MPlayer, ComCtrls,
  StdCtrls, Gauges, GIFImage, frminit;

type
  TForm1 = class(TForm)
    EnhImage1: TEnhImage;
    Exit: TTransparentButton;
    OpenFile: TTransparentButton;
    Pause: TTransparentButton;
    Play: TTransparentButton;
    Stop: TTransparentButton;
    oxForm1: ToxForm;
    OpenDialog1: TOpenDialog;
    MediaPlayer1: TMediaPlayer;
    Label1: TLabel;
    Gauge1: TGauge;
    Timer1: TTimer;
    GIFImage1: TGIFImage;
    FormInitialize1: TFormInitialize;
    procedure OpenFileClick(Sender: TObject);
    procedure PlayClick(Sender: TObject);
    procedure PauseClick(Sender: TObject);
    procedure StopClick(Sender: TObject);
    procedure ExitClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);

  private
    FFileName: AnsiString;
    procedure SetFileName(const FileName: AnsiString);
    procedure OpenCode(const CreateFile: AnsiString);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


procedure Tform1.SetFileName(const FileName: AnsiString);
begin
     FFileName := FileName;
     Caption := Format('%s - %s', [ExtractFileName(FileName), Application.Title]);
     OxForm1.Refresh;
end;

procedure TForm1.OpenFileClick(Sender: TObject);
begin
with mediaplayer1 do begin
if OpenDialog1.Execute then
MediaPlayer1.FileName := OpenDialog1.FileName;
MediaPlayer1.DeviceType := dtAutoSelect;
MediaPlayer1.Open;
FFileName := FileName;
Label1.Caption := Format('%s', [ExtractFileName(FileName)]);
end;
SetFileName(OpenDialog1.FileName);
end;

procedure TForm1.PlayClick(Sender: TObject);
begin
with mediaplayer1 do begin
 gauge1.MaxValue := length;
 gauge1.Progress := 0;
 timer1.enabled := true;
 MediaPlayer1.Play;
 end;
end;

procedure TForm1.PauseClick(Sender: TObject);
begin
MediaPlayer1.Pause;
end;

procedure TForm1.StopClick(Sender: TObject);
begin
MediaPlayer1.Stop;
MediaPlayer1.Rewind;
end;

procedure TForm1.ExitClick(Sender: TObject);
begin
try
 FormInitialize1.SaveToRegistry;
 finally
 FormInitialize1.Free;
 end;
Close;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
parameters: string;
x: integer;
WinDirLen: Integer;
WinDir: PChar;
dir : string;
begin
   GetMem(WinDir, 255);
   WinDirLen := GetSystemDirectory(WinDir,255);
   dir := Windir;
   FreeMem(WinDir);
   GifImage1.FileName:= dir + '\lcarsnew.gif';
 FormInitialize1.LoadFromRegistry;
 parameters := '';
     for x := 1 to paramCount do
     begin
     parameters := parameters + paramStr(x);
     if x < paramCount then parameters := parameters +' ';
     end;
     if Parameters <> '' then OpenCode(Parameters);
end;


procedure Tform1.OpenCode(const CreateFile: AnsiString);
begin
     with mediaplayer1 do begin
     MediaPlayer1.FileName := (CreateFile);
     MediaPlayer1.DeviceType := dtAutoSelect;
     MediaPlayer1.Open;
     SetFileName(CreateFile);
     gauge1.MaxValue := length;
     gauge1.Progress := 0;
     timer1.enabled := true;
     gauge1.MaxValue := length;
     gauge1.Progress := 0;
     timer1.enabled := true;
     FFileName := FileName;
     Label1.Caption := Format('%s', [ExtractFileName(FileName)]);
     MediaPlayer1.Play;
     end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
Gauge1.Progress := Mediaplayer1.Position;
end;

end.

0
 
LVL 3

Expert Comment

by:Matvey
ID: 1354606
Well I also had no time to try yours, but I want to add smth to my answere, and I quote:
"If your application receives an mci_Notify_Successful message, and if the Mode field of the device is set
      to mci_Mode_Stop, you can be certain that the current file has finished playing. That is why the OnNotify
      method shown above checks for such a condition:

      if (MediaPlayer1.NotifyValue = nvSuccessful) and
            (MediaPlayer1.Mode = mpStopped) then
          Edit1.Text := 'File finished playing';  "

So, set notify to true,
assign a OnNotify handler and add the code above, and instead of  instead of changing text just .PLAY again...

Good luck,
Matvey
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question