Solved

how can i play mp3 in delphi with not use some dll vcl component?

Posted on 2003-11-04
11
795 Views
Last Modified: 2010-04-06
hi,experts
how can i play mp3 in delphi with not use some dll vcl component?
have any free vcl can play mp3?

thanks!
0
Comment
Question by:jbas
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 5

Expert Comment

by:snehanshu
ID: 9677693
You could use TMediaPlayer (in system).
HTH
...Snehanshu
P.S.
Set MediaPlayer's AutoOpen property to true and an mp3 file name. Then you can play the file.
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9677730
uses mmsystem;


PlaySound(sound.wav)
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9677743
I mean

PlaySound('sound.mp3');
0
 

Author Comment

by:jbas
ID: 9677811
PlaySound('sound.mp3');
can not work!
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9677860
PlaySound('sound.mp3', 0, 0);
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:jbas
ID: 9677918
PlaySound('sound.mp3', 0, 0);
can not work!

and if i use TMediaPlayer ,how can i play in stream?
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 9678200
jbas,
  Here's a ready-to-use program listing to play a list of files from this previously answered question:
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20110803.html

Hope that helps,
...Shu

>>It loads the list of files from the specified path, and then shuffles them and begins playing.

>>The list is stored in a TListBox, so that you can see where it's up to.

>>btnStart starts the process.
>>btnStop stops it.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, MPlayer;

type
  TForm1 = class(TForm)
    btnStart: TButton;
    MediaPlayer1: TMediaPlayer;
    lbMusic: TListBox;
    btnStop: TButton;
    procedure btnStartClick(Sender: TObject);
    procedure MediaPlayer1Notify(Sender: TObject);
    procedure btnStopClick(Sender: TObject);
  private
    procedure PlayMusic;
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


const
  MusicPath = 'C:\all files\music\';
  MusicWildcard = '*.mp3';

procedure GetFiles(const Path, Wildcard: String; L: TStrings);
var
 sr: TSearchRec;
begin
  if FindFirst(Path + Wildcard, faAnyFile, sr) = 0 then
  begin
    L.Add(sr.Name);
    while FindNext(sr) = 0 do
      L.Add(sr.Name);
  end;
  FindClose(sr);
end;

procedure ShuffleList(L: TStrings);
var
  i, j: integer;
  sTmp: String;
begin
  Randomize;
  for i := 0 to L.Count - 1 do
  begin
    j := Random(L.Count);
    if i <> j then
    begin
      sTmp := L[i];
      L[i] := L[j];
      L[j] := sTmp;
    end;
  end;
end;

procedure TForm1.btnStartClick(Sender: TObject);
begin
  lbMusic.Items.BeginUpdate;
  try
    lbMusic.Clear;

    // Get all mp3's from my music directory
    GetFiles(MusicPath, MusicWildcard, lbMusic.Items);

    // Shuffle the list
    ShuffleList(lbMusic.Items);
  finally
    lbMusic.Items.EndUpdate;
  end;

  // Start playing from the list
  lbMusic.ItemIndex := 0;
  if MediaPlayer1.Mode = mpPlaying then
    MediaPlayer1.Stop;
  MediaPlayer1.Wait := True;
  MediaPlayer1.Close;
  PlayMusic;
end;

procedure TForm1.MediaPlayer1Notify(Sender: TObject);
begin
  if (MediaPlayer1.Error = 0)
    and (lbMusic.ItemIndex < lbMusic.Items.Count - 1) then
  begin
    lbMusic.ItemIndex := lbMusic.ItemIndex + 1;
    PlayMusic;
  end;
end;

procedure TForm1.PlayMusic;
begin
  if lbMusic.ItemIndex > -1 then
  begin
    MediaPlayer1.FileName := MusicPath + lbMusic.Items[lbMusic.ItemIndex];
    MediaPlayer1.Open;
    MediaPlayer1.Notify := True;
    MediaPlayer1.Play;
  end;
end;

procedure TForm1.btnStopClick(Sender: TObject);
begin
  if MediaPlayer1.Mode = mpPlaying then
    MediaPlayer1.Stop;
  MediaPlayer1.Wait := True;
  MediaPlayer1.Close;
end;

end.
0
 

Author Comment

by:jbas
ID: 9679075
snehanshu,thank you,
but i want to know how can i play in stream,not like this:
 mediaplay.filename:='d:\1.mp3';
mediaplay.play;

i want to like this :
mediaplay.loadfromstream???????(but not this function,how can i do it );
0
 
LVL 3

Accepted Solution

by:
ThoseBug earned 100 total points
ID: 9685838
http://delphi.about.com/library/weekly/aa112800a.htm you have in this site the code and the instruccions to made an mp3 player.

hope help you
0
 

Author Comment

by:jbas
ID: 9693274
thanks to ThoseBug and all
but this is not my want ,i need how tmediaplayer play stream music!
0
 

Author Comment

by:jbas
ID: 9721178
please help me.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Copy file in dll not working but working on exe ! 18 88
delphi exception 7 62
Reconfigure Delphi Install? 2 46
Error E2158 compiling with Delphi XE10 Seattle 2 86
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now