Autor Beitrag
Raezor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: Fr 09.03.07 19:04 
Ich habe gesucht und 34619 Threads gefunden, doch keiner von denen hat bei mir funktioniert.

Ich will ganz einfach musik abspielen. (wav)
Dazu habe ich so ein Ding aus der Liste System den MediaPlayer
genommen und in das Fenster gezogen.
Aber wie bekomme ich den dazu, zu spielen?

Könnt ihr mir den kompletten code für den mediaplayer geben?
Calculon
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Fr 09.03.07 19:18 
Na logo!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TForm1.Button1Click(Sender: TObject);
var
  OpenDialog1: TOpenDialog;
begin
  OpenDialog1:=TOpenDialog.Create(Self);
  OpenDialog1.Filter:='WAV-Files|*.wav';
  if OpenDialog1.Execute then
    begin
      try
        MediaPlayer1.FileName:=OpenDialog1.FileName;
        MediaPlayer1.AutoOpen := True;
        MediaPlayer1.Hide;
        MediaPlayer1.AutoRewind := True;
        MediaPlayer1.Open;
        MediaPlayer1.Play;
      except
        ShowMessage('Nope! Didn''t work');
      end;
  end; 

end;


Gruß

Calculon
--
Raezor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: Sa 10.03.07 07:12 
erstmal danke, doch es funktioniert nicht:

user defined image
Jakob_Ullmann
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: Sa 10.03.07 08:21 
Ich weiß ja nicht, was du dir dabei gedacht hast, aber ich würde auch nie auf die Idee kommen, einen OpenDialog lokal zu vereinbaren.
Setz den einfach auf das Formular (OpenDialog). Den findest du bei "Dialoge".
Dann setzt du den MediaPlayer auf das Formular und tippst bei z.B. einem Button-Klick
folgenden Quellcode ein:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
begin
  try
    OpenDialog1.Execute;
    MediaPlayer1.FileName := OpenDialog1.FileName;
    MediaPlayer1.Play;
  except
    Application.MessageBox('Datei konnte nicht geöffnet werden.','Fehler',MB_OK+MB_ICONERROR);
  end;
end;
Jakob_Ullmann
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: Sa 10.03.07 08:27 
Wenn der Fehler angezeigt wird, kannst du auch auf F1 klicken.
Dann gibt er dir ein paar Tipps, woran das liegen könnte.
Schau sonst mal im Hilfe-File.
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Sa 10.03.07 10:06 
@Raezor: Dein Quelltext stimmt schon. Dir fehlt nur in der allerersten Zeile eine schließende Klammer vor dem Stichpunkt.

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Raezor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: Sa 10.03.07 13:50 
Ich versuche nun Jakob_Ullmann Bsp. zu nehmen.
Also mache ich eine neue Anwendung auf und ziehe den
OpenDialog ins Formular.
Dann ziehe ich den Mediaplayer ins Formular.
Daraufhin werde ich einen Butten in das Formular ziehen, wo ich peer Doppelklick
in sein Feld folgendes reinschreibe:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
begin
  try
    OpenDialog1.Execute;
    MediaPlayer1.FileName := OpenDialog1.FileName;
    MediaPlayer1.Play;
  except
    Application.MessageBox('Datei konnte nicht geöffnet werden.','Fehler',MB_OK+MB_ICONERROR);
  end;
end;

Nun starte ich das ding.
....und wenn ich auf den Button klicke, zeigt er ein feld,
wo ich eine datei auswählen muss, wobei er automatisch die wav datei abspielen soll!

Moderiert von user profile iconmatze: Delphi-Tags hinzugefügt
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Sa 10.03.07 13:52 
Und wo genau liegt jetzt das Problem ?

Hast du meinem Post oben zur Kenntnis genommen?

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Jakob_Ullmann
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: Sa 10.03.07 14:35 
War es das, was du willst, oder nicht?
MediaPlayer1.Play kannst du ja auch in eine andere Methode schreiben.
(Wenn es das ist, was du willst)
Und das mit der Klammer:
Ich kenne mich mit Compilermeldungen nicht so aus, aber nach meiner Theorie würde er dann schon bei "var" meckern.
Aber versuchen würde ich es. :wink:
Raezor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: Sa 10.03.07 15:17 
Jaja @ Mod, du hast schon recht der Code funktioniert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
procedure TForm1.Button4Click(Sender: TObject);

var
  OpenDialog1: TOpenDialog;
begin
  OpenDialog1:=TOpenDialog.Create(Self);
  OpenDialog1.Filter:='1.wav';
  if OpenDialog1.Execute then
    begin
      try
        MediaPlayer1.FileName:=OpenDialog1.FileName;
        MediaPlayer1.AutoOpen := True;
        MediaPlayer1.Hide;
        MediaPlayer1.AutoRewind := True;
        MediaPlayer1.Open;
        MediaPlayer1.Play;
      except
        ShowMessage('Nope! Didn''t work');
      end;
  end;

end;

, doch die datei startet nicht vonn alleine.

ich möchte, dass wenn ich meine exe starte, gleich die wav anfäng abzuspielen

Moderiert von user profile iconmatze: Code- durch Delphi-Tags ersetzt
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Sa 10.03.07 17:16 
dann schreib deinen code nicht in eine Button-Click anweisung rein, sondern in das OnCreate Ereignis von deinem Formular.

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Raezor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: Sa 10.03.07 17:59 
jetzt hab ich es in einen timer geschrieben, doch er wird sie nicht abspielen, da man sie auswählen muss.
Kann man nicht ein festen pfad der wav datei bestimmen, anstatt sie durch so ein öffnungsdialog zu suchen?
stigge
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 426

WinXP
Delphi 2007
BeitragVerfasst: Sa 10.03.07 18:39 
Also mal die einfache Variante:
ausblenden Delphi-Quelltext
1:
2:
3:
mediaplayer1.filename := 'der Name der Musikdatei wenn im gleichen Ordner wie das Programm oder der Pfad zu ihr';
mediaplayer1.open;
mediaplayer1.play;

Und das alles in die form1.oncreate Prozedur schreiben, dann müsste es gehen :wink:
Raezor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: Sa 10.03.07 19:02 
ich denke, das wäre das simpelste
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject);
begin
mediaplayer1.filename := '1.wav';
mediaplayer1.open;
mediaplayer1.play;
end;

end.


jetzt zeigt er aber an:
[Fehler] Unit1.pas(28): Undefinierter Bezeichner: 'mediaplayer1'
%diese smilies versauen die Beiträge....%

Moderiert von user profile iconmatze: Code- durch Delphi-Tags ersetzt
stifflersmom
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 194

XP /XP PRO/ SuSE div.
D1 - D7, BDS 2006
BeitragVerfasst: Sa 10.03.07 19:08 
Liegt denn jetzt noch ein mediaplayer auf Deinem formular?

Zeig doch am besten mal Deinen ganzen Code.

Moin
Raezor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: Sa 10.03.07 20:05 
hm..klar..hatte ein neues Formular gemacht.
Wenn ich jetzt den Mediaplayer hinzufüge, gehts!
Danke
stigge
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 426

WinXP
Delphi 2007
BeitragVerfasst: Sa 10.03.07 21:15 
user profile iconRaezor hat folgendes geschrieben:
hm..klar..hatte ein neues Formular gemacht.
Wenn ich jetzt den Mediaplayer hinzufüge, gehts!
Danke


Ich hätte gedacht das das klar ist :shock: