Solved

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

Posted on 2003-11-04
11
902 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

761 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