Einzelnen Beitrag anzeigen

Mydoene
(Gast)

n/a Beiträge
 
#8

Re: AUDIO: Wie kann ich Dateinamen im Mediaplayer benutzen?

  Alt 14. Jan 2007, 16:04
Um mal Quelltext mitzubringen:

Delphi-Quellcode:
MediaPlayer1.FileName := Edit1.Text;
MediaPlayer1.Open;
MediaPlayer1.Wait := false;
MediaPlayer1.Play;
Genauso hab' ich's jetzt. Es funktioniert zwar, allerdings fängt jetzt der Mediaplayer jede Sekunde an, die Datei abzuspielen und wird dann wieder von sich selbst überspielt. Wie kann ich jetzt dem Timer-Event mitteilen, dass es den Mediaplayer nur starten soll, wenn der noch nicht an ist?

//edit:

Hier ist jetzt mal der komplette Quelltext, neu, überarbeitet, und mit allen Objekten, die man so braucht. Die Shapes sind dazu da, eine Binäre Uhr anzuzeigen. Muss nicht unbedingt interessieren...

Delphi-Quellcode:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Image1: TImage;
    Label4: TLabel;
    Shape1: TShape;
    Shape2: TShape;
    Shape3: TShape;
    Shape4: TShape;
    Shape5: TShape;
    Shape6: TShape;
    Shape7: TShape;
    Shape8: TShape;
    Shape9: TShape;
    Shape10: TShape;
    Shape11: TShape;
    Shape12: TShape;
    Shape13: TShape;
    Shape14: TShape;
    Shape15: TShape;
    Shape16: TShape;
    Shape17: TShape;
    Label5: TLabel;
    MediaPlayer1: TMediaPlayer;
    Shape18: TShape;
    Edit1: TEdit;
    Label6: TLabel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Edit2: TEdit;
    Edit3: TEdit;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Button2MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
  alpha:TAlarmclock;
  procedure write;
  public

  end;

var
  Form1: TForm1;
  x:Integer;
  HourWeck, MinWeck: Integer;
  dataPfad: String;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject); //****JJ****\\
begin // . \
  if Button1.Caption='Schließenthen // .
  begin // .
    label6.Visible:=false; // .
    edit1.Visible:=false; // .
    edit2.Visible:=false; // .
    edit3.Visible:=false; // .
    label7.Visible:=false; // .
    label8.Visible:=false; // .
    Button1.Caption:='Stellen'; // .
    HourWeck:=strtoint(edit2.Text); // .
    alpha.SetAlarmTime(HourWeck,MinWeck); // .
  end // .
  else if Button1.Caption='Stellenthen begin // .
    label6.Visible:=true; // .
    edit1.Visible:=true; // .
    edit2.Visible:=true; // .
    edit3.Visible:=true; // .
    label7.Visible:=true; // .
    label8.Visible:=true; // .
    Button1.Caption:='Schließen'; // .
    MinWeck:=strtoint(edit3.Text); // . \
  end //****JJ****\\
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  label4.Caption := FormatDateTime('dd.mm.yyyy', now);
  alpha:=TAlarmclock.create;
  write;
  alpha.Onchange:= Write;
  alpha.Start;
  alpha.setsec(StrToInt(formatdatetime('ss',time)));
  alpha.setmin(StrToInt(formatdatetime('nn',time)));
  alpha.sethour(StrToInt(formatdatetime('hh',time)));
  x:= 86400-(alpha.gethour * 3600) - (alpha.getmin*60) - (alpha.getsec);
  label5.caption:=IntToStr(x);

  //****JJ****\\
{}HourWeck := strtoint(Edit2.Text);
{}MinWeck := strtoint(Edit3.Text);
{}alpha.SetAlarmTime(HourWeck,MinWeck);
  //****JJ****\\
end;

procedure TForm1.write;
var i,j,z:Integer;
begin
 label1.Caption:=IntToStr(alpha.getsec);
 label2.Caption:=IntToStr(alpha.getmin);
 label3.caption:=IntToStr(alpha.gethour);
 j:=alpha.getsec;
  if (j mod 2) = 1 then shape1.Brush.Color:=clblack
   else shape1.brush.Color:=clsilver;
 j:=(j div 2);
  if (j mod 2) = 1 then shape2.Brush.Color:=clblack
   else shape2.brush.Color:=clsilver;
 j:=(j div 2);
  if (j mod 2) = 1 then shape3.Brush.Color:=clblack
   else shape3.brush.Color:=clsilver;
 j:=(j div 2);
  if (j mod 2) = 1 then shape4.Brush.Color:=clblack
   else shape4.brush.Color:=clsilver;
 j:=(j div 2);
  if (j mod 2) = 1 then shape5.Brush.Color:=clblack
   else shape5.brush.Color:=clsilver;
 j:=(j div 2);
  if (j mod 2) = 1 then shape6.Brush.Color:=clblack
   else shape6.brush.Color:=clsilver;

 i:=alpha.getmin;
  if (i mod 2) = 1 then shape7.Brush.Color:=clblack
   else shape7.brush.Color:=clsilver;
 i:=(i div 2);
  if (i mod 2) = 1 then shape8.Brush.Color:=clblack
   else shape8.brush.Color:=clsilver;
 i:=(i div 2);
  if (i mod 2) = 1 then shape9.Brush.Color:=clblack
   else shape9.brush.Color:=clsilver;
 i:=(i div 2);
  if (i mod 2) = 1 then shape10.Brush.Color:=clblack
   else shape10.brush.Color:=clsilver;
 i:=(i div 2);
  if (i mod 2) = 1 then shape11.Brush.Color:=clblack
   else shape11.brush.Color:=clsilver;
 i:=(i div 2);
  if (i mod 2) = 1 then shape12.Brush.Color:=clblack
   else shape12.brush.Color:=clsilver;

    z:=alpha.gethour;
  if (z mod 2) = 1 then shape13.Brush.Color:=clblack
   else shape13.brush.Color:=clsilver;
 z:=(z div 2);
  if (z mod 2) = 1 then shape14.Brush.Color:=clblack
   else shape14.brush.Color:=clsilver;
 z:=(z div 2);
  if (z mod 2) = 1 then shape15.Brush.Color:=clblack
   else shape15.brush.Color:=clsilver;
 z:=(z div 2);
  if (z mod 2) = 1 then shape16.Brush.Color:=clblack
   else shape16.brush.Color:=clsilver;
 z:=(z div 2);
  if (z mod 2) = 1 then shape17.Brush.Color:=clblack
   else shape17.brush.Color:=clsilver;
 if x>0 then x:=x-1
 else x:=86400;
 label5.caption:=IntToStr(x);
 if shape18.Visible=true then shape18.visible:=false
 else shape18.Visible:=true;

  //****JJ****\\
{}if alpha.AlarmOn = true then
{}  begin
{}    dataPfad := Edit1.Text;
{}    MediaPlayer1.FileName := dataPfad;
{}    MediaPlayer1.Open;
{}    MediaPlayer1.Play;
{}  end;
  //****JJ****\\
end;

procedure TForm1.Button2MouseDown(Sender: TObject; Button: TMouseButton; //****JJ****\\
  Shift: TShiftState; X, Y: Integer); // . \
begin // .
  Label9.Visible:=true; // .
  Label10.Visible:=true; // .
  Label11.Visible:=true; // .
  Label12.Visible:=true; // .
  Label10.Caption:=inttostr(HourWeck); // .
  Label11.Caption:=inttostr(MinWeck); // .
end; // .
                                                                                  // .
procedure TForm1.Button2MouseUp(Sender: TObject; Button: TMouseButton; // .
  Shift: TShiftState; X, Y: Integer); // .
begin // .
  Label9.Visible:=false; // .
  Label10.Visible:=false; // .
  Label11.Visible:=false; // .
  Label12.Visible:=false; // . \
end; //****JJ****\\

end.
Die mit JJ markierten Passagen habe ich gemacht, die anderen ein Kumpel.

Hier ist AlarmClock, das Objekt, das man dafür braucht:

Delphi-Quellcode:

unit UAlarmclock;

interface
uses UinfoClock;
Type
TAlarmClock =class(TInfoClock)
  private
  aHour,aMin:cardinal;
  public
  constructor Create; override;
  procedure SetAlarmTime(h,m:cardinal);
  procedure GetAlarmTime(var h,m:cardinal) ;
  function AlarmOn:boolean;
  end;

//Implementation der Weckerklasse:
implementation
  constructor TAlarmClock.Create;
  begin
    inherited Create;
    aHour:=0;aMin:=0;

  end;

  procedure TAlarmClock.SetAlarmTime(h,m:Cardinal);
  begin
    aHour:=h;
    aMin:=m;
  end;

  procedure TAlarmClock.GetAlarmTime(var h,m:cardinal);
  begin
    h:=ahour;
    m:=amin
  end;

  function TAlarmClock.AlarmOn:boolean;
  begin
    if (ahour=gethour) and (amin=getmin) then result:=true else result:=false;
  end;
end.
Und hier ist die Uhr, der Vorgänger:

Delphi-Quellcode:

unit Uclock;

interface
uses Umodcounter,ExtCtrls;
Type Tclock=class
  private
    hour:Tmodcounter;
    min:Tmodcounter;
    sec:Tmodcounter;
  public
  constructor create();virtual;
  destructor destroy();override;
  procedure click();virtual;
  procedure sethour(n:cardinal);virtual;
  procedure setmin(n:cardinal);virtual;
  procedure setsec(n:cardinal);virtual;
  function gethour:cardinal;virtual;
  function getmin:cardinal;virtual;
  function getsec:cardinal;virtual;
  end;
 Tclockwithtimer = class(Tclock)
 private
  ctime : TTimer;
  procedure Movetime(Sender:Tobject);
 public
  constructor Create; override;
  destructor Destroy; override;
  procedure start;
  procedure stop;
 end;

implementation

constructor Tclock.create();
begin
sec:=Tmodcounter.Create;
min:=Tmodcounter.Create;
hour:=Tmodcounter.Create;
min.init(60);
sec.init(60);
hour.init(24);
end;

destructor TClock.destroy;
begin
  inherited Destroy;
end;

procedure tclock.click;
begin
sec.click;
 if sec.getcount = 0 then begin
    min.click;
    if min.getcount = 0 then hour.click;
 end;
end;

procedure Tclock.sethour (n:cardinal);
begin
hour.setcount(n);
end;

procedure Tclock.setmin (n:cardinal);
begin
min.setcount(n);
end;

procedure Tclock.setsec (n:cardinal);
begin
sec.setcount(n);
end;

function Tclock.gethour:cardinal;
begin
gethour:=hour.getcount;
end;

function Tclock.getmin:cardinal;
begin
getmin:=min.getcount;
end;

function Tclock.getsec:cardinal;
begin
getsec:=sec.getcount;
end;

constructor Tclockwithtimer.Create;
begin
 inherited Create;
 Ctime:= Ttimer.Create(nil);
 Ctime.interval:=1000;
 ctime.enabled:=false;
 Ctime.ontimer:= Movetime;
end;

destructor Tclockwithtimer.Destroy;
begin
sec.free; min.free; hour.Free;
inherited destroy;
end;

procedure Tclockwithtimer.start;
begin
 ctime.enabled:=true;
end;

procedure tclockwithtimer.stop;
begin
 ctime.enabled:=true;
end;

procedure Tclockwithtimer.Movetime(Sender:Tobject);
begin
 click;
end;
end.
...der ModCounter und der Counter:

Delphi-Quellcode:

unit UModCounter;

interface
uses UCounter2;
Type TModCounter=class(TCounter2)
     private
       max:cardinal;
       public
       procedure Init(n:Cardinal); //Maximum festlegen
       procedure Click;override; //Click wird überschrieben
       procedure setcount(n:Cardinal);override;
end;
implementation

procedure Tmodcounter.init(n:cardinal);
begin
  max:=n;
end;
procedure Tmodcounter.click;
begin
  inherited Click; // Aufruf der gleichnamigen Methode von TCounter
  if getcount>=max then Clear;
end;
procedure Tmodcounter.setcount(n:cardinal);
begin
  inherited setcount(n) ; // Aufruf der gleichnamigen Methode von TCounter
  if getcount>=max then Clear;
end;
end.
Delphi-Quellcode:

unit Ucounter2;


interface
Type
  TCounter2 = class
  private
    count:cardinal;
  public
    constructor Create;
    destructor Destroy; override;
    procedure Clear;
    procedure Click;virtual;
    procedure SetCount(n:Cardinal);virtual;
    function GetCount:cardinal;
  end;
implementation
constructor TCounter2.Create;
begin
  count:=0;
end;

destructor TCounter2.destroy;
begin
  inherited Destroy;
end;

procedure Tcounter2.Clear;
begin
  count:=0;
end;

procedure Tcounter2.Click;
begin
  Inc(count);
end;

procedure TCounter2.SetCount(n:cardinal);
begin
  count:=n;
end;

function Tcounter2.GetCount:cardinal;
begin
  Getcount:= count;
end;

end.
Das war's. Wenn mir jetzt auch noch einer sagen könnte, wieso der Player schon von Anfang an zu spielen anfängt, obwohl .Enabled, .AutoEnable usw. alle auf false sind, kriegt 'nen feuchten Händedruck ^^

//Edit: Hab' jetzt bei der Procedure unter Schließen auch ein "alpha.SetAlarmTime(HourWeck,MinWeck);" eingefügt. Also jetzt geht alles, außer dass das Mistvieh von Anfang an zu playen anfängt... So'n schiet... WIESO macht der sowas?
  Mit Zitat antworten Zitat