Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Mediaplayer1.Play; how to loop?

Posted on 1997-12-25
9
Medium Priority
?
352 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Independent Software Vendors: 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

597 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