| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 48019 | 2004-08-12 02:03:00 | Delphi 7 | Barnzy (6015) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 260736 | 2004-08-12 02:03:00 | I started following Geoffs Delphi for beginners and then got busy doing work stuff and, shame on me, didn't buy PC World for months. I recently had another go and found myself stumped. I am trying to write an MP3 Player but am stuck on how to get the file name from OpenDialoge to FileName for MediaPlayer. Any clues? |
Barnzy (6015) | ||
| 260737 | 2004-08-12 07:55:00 | MediaPlayer1.Filename:= OpenDialog1.FileName; | mikebartnz (21) | ||
| 260738 | 2004-08-13 00:20:00 | That's what I thought, but somehow it will not play, error message saying that the file cannot be played. Am I supposed to declare the variable? | Barnzy (6015) | ||
| 260739 | 2004-08-13 06:41:00 | I don't think it can play MP3 files hence the error message. I know it can play wav files though. | mikebartnz (21) | ||
| 260740 | 2004-08-13 06:42:00 | >I supposed to declare the variable? No need to. |
mikebartnz (21) | ||
| 260741 | 2004-08-13 12:12:00 | Cheers Mate. Delphi does handle MP3's and if you don't define media type it will do "almost" anything. Any way I think the problem was a problem with my system speed or something (win 98se, 64meg on 300 "ish." meg cpu) So Here's what I came up with:: unit Music; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, StdCtrls, MPlayer, ComCtrls, FileCtrl; type TForm1 = class(TForm) OpenDialog1: TOpenDialog; Button1: TButton; MediaPlayer1: TMediaPlayer; Button2: TButton; Label1: TLabel; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin OpenDialog1.Execute; Label1.Caption:= OpenDialog1.FileName; MediaPlayer1.FileName:= Label1.Caption; MediaPlayer1.open; end; procedure TForm1.Button2Click(Sender: TObject); begin Close; end; end. Simple really (a bit twisted maybe, but it works) The diference seems to be the the time it takes to access the file and the time it takes to initianise the player component, so by sending the string to the label and from there to the Player the lag is no longer an issue. What do you think. Cheers Barnzy. |
Barnzy (6015) | ||
| 260742 | 2004-08-13 13:35:00 | > Delphi does handle MP3's and if you don't define > media type it will do "almost" anything. This is not technically correct. I have had this problem before myself (right after reinstalling win), and the problem seems to be to do with what audio codecs you have installed on your system. Delphi seems to use some non-standard ones, and is also dependant on the codec being installed on the target machine you are deploying your app on - if the target machine doesn't have the codec already installed, you get the error message. The same problem also occurs with WMA and OGG files (the only other formats apart from mp3 I've tried). Bletch |
Bletch (244) | ||
| 260743 | 2004-08-13 13:47:00 | Hi to start with I do not know Delphi, but I program a few other languages . You should try to give the objects better names . Also is the below needed as nothing seems to be declared private { Private declarations } public { Public declarations } Please do not take offence, as I am just trying to learn and dont mean to criticise your code . |
Rob99 (151) | ||
| 260744 | 2004-08-13 13:52:00 | I am not entirely sure if it is needed, but I would guess so as it is part of the auto-generated code that delphi creates whenever you make a new form. Bletch |
Bletch (244) | ||
| 260745 | 2004-08-13 14:33:00 | Leaving those auto created declarations there makes no difference as they don't get compiled but as you add more code you may find you want them so it is just as easy to leave them there. The only code he actualy wrote was in the two buttton click methods as Delphi does the rest. |
mikebartnz (21) | ||
| 1 2 | |||||