Solved

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

Posted on 2003-11-04
11
756 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
TcomboBox uninverted item 3 45
Thread safe  opinion 7 111
Copy file in dll not working but working on exe ! 18 83
Newbie Thread Programming 1 117
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

16 Experts available now in Live!

Get 1:1 Help Now