Solved

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

Posted on 2003-11-04
11
842 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi: how to implement a User Shortcut mapper? 1 110
LAN or WAN ? 11 92
SUM 2 INTEGER ARRAYS INTO 1 10 101
CheckListBox usage 3 59
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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

832 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