Solved

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

Posted on 2003-11-04
11
867 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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
 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 327
Reconfigure Delphi Install? 2 61
How to load 2 images in same column in Delphi 2 57
Twebbrowser add css to the header 3 29
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

827 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