🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.multimedia
Article #604

Re: MP3 VCL Player

#604
From: Mark Jacobs
Date: Mon, 05 Apr 2004 14:47
174 lines
8255 bytes
MediaPlayer will use codecs installed by the OS to play back MP3s. I had no problem opening all varieties of
multimedia files on my PC with a bog-standard MediaPlayer component. The only things it would not play were
MOVs (Quicktime) RMs (Real Media) and OGG (Vorbis) files. So, why do you need to circumvent a perfectly good
component? Here is the source code for the mm player I wrote ( exe free for download at
http://www.jacobsm.com/mjplayer.exe ) :-

//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop

#include "Main.h"
//---------------------------------------------------------------------------
#pragma link "CSPIN"
#pragma link "zBtn2"
#pragma link "zPanel"
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
 : TForm(Owner)
{
  cmdl=false; plying=false; inply=false; ckt=-1; Top=Screen->Height-Height*2;
  plist=new TStringList(); plems=(int *)malloc(1*sizeof(int)); nodel=false;
}
//----------------------------------------------------------------------------
void __fastcall TMainForm::FileOpen(TObject *Sender)
{
  int ii;
  if (plying) return;
  if (!cmdl)
  {
    if (!OpenDialog->Execute()) return;
    plist->Assign(OpenDialog->Files); plist->Sorted=true;
  }
  cmdl=false; plist->SaveToFile(ckf); ckt=FileAge(ckf);
  plems=(int *)realloc(plems,plist->Count*sizeof(int)); if (!plems) return;
  for (ii=0;ii<plist->Count;++ii) plems[ii]=ii;
  plylst(Sender);
}
//----------------------------------------------------------------------------
void __fastcall TMainForm::dolabs()
{
  static AnsiString ollb2="",ollb3=""; AnsiString nllb2="",nllb3=""; bool doit=false;
  if (MediaPlayer1->FileName.IsEmpty()) return;
  int wh2=MediaPlayer1->Position/1000,wh3=MediaPlayer1->Length/1000;
  if (wh2>=3600) { nllb2+=AnsiString(wh2/3600)+"h "; wh2%=3600;}
  if (wh2>=60) { nllb2+=AnsiString(wh2/60)+"m "; wh2%=60;}
  nllb2+=AnsiString(wh2)+"s";
  if (wh3>=3600) { nllb3+=AnsiString(wh3/3600)+"h "; wh3%=3600;}
  if (wh3>=60) { nllb3+=AnsiString(wh3/60)+"m "; wh3%=60;}
  nllb3+=AnsiString(wh3)+"s";
  if (ollb2!=nllb2) { Label2->Caption=nllb2; ollb2=nllb2; doit=true;}
  if (ollb3!=nllb3) { Label3->Caption=nllb3; ollb3=nllb3; doit=true;}
  if (doit) Application->Title=ExtractFileName(MediaPlayer1->FileName)+"  "+nllb2+" of "+nllb3;
}
//----------------------------------------------------------------------------
void __fastcall TMainForm::plylst(TObject *Sender)
{
  int ii,jj,tsp;
  AnsiString sndexts="*.mid*;*.wav;*.mp3;*.mp2;*.wma;*.au;*.aif*;*.asx;*.rmi;*.snd;*.cda";
  for (brk=false,jj=0;!brk && jj<plist->Count;++jj)
  {
    ii=plems[jj]; MediaPlayer1->FileName="";
    Caption="MJPlayer "+AnsiString(jj+1)+"/"+AnsiString(plist->Count)+" "+plist->Strings[ii];
    MediaPlayer1->FileName=plist->Strings[ii];
    try
    {
      MediaPlayer1->Open();
    }
    catch (Exception &excp)
    {
      MediaPlayer1->FileName=""; ShowMessage(excp.Message); continue;
    }
    MediaPlayer1->TimeFormat=tfMilliseconds; MediaPlayer1->Notify=true;
    tsp=max(100,MediaPlayer1->Length/10); zKnob1->Max=tsp; zKnob1->Value=tsp/2; zKnob1Change(Sender);
    do
    {
      inply=true; MediaPlayer1->Play(); plying=true; while (plying) Application->ProcessMessages();
      inply=false; if (brk) return;
    }
    while (CheckBox1->Checked && plist->Count==1);
    if (CheckBox1->Checked && jj==plist->Count-1) jj=-1;
  }
}
//----------------------------------------------------------------------------
void __fastcall TMainForm::MediaPlayer1Notify(TObject *Sender)
{
  if (MediaPlayer1->Position>=MediaPlayer1->Length-1) { Application->Title="MJPlayer"; plying=false;}
}
//----------------------------------------------------------------------------
void __fastcall TMainForm::MediaPlayer1Click(TObject *Sender, TMPBtnType Button, bool &DoDefault)
{
  if (plist->Count<1) { DoDefault=false; return;}
  if (Button==btStop) { MediaPlayer1->Position=MediaPlayer1->Length; plying=false; brk=true;}
  else if (Button==btPause) inply=false;
  else if (Button==btPlay)
  {
    DoDefault=false; if (plying) { inply=true; MediaPlayer1->Play();} else plylst(Sender);
  }
  else if (Button==btStep)
  {
    DoDefault=false;
    MediaPlayer1->Position=min(MediaPlayer1->Length-1,MediaPlayer1->Position+stp); dolabs();
    if (inply) MediaPlayer1->Play();
  }
  else if (Button==btBack)
  {
    DoDefault=false;
    MediaPlayer1->Position=max(0,MediaPlayer1->Position-stp); dolabs();
    if (inply) MediaPlayer1->Play();
  }
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCloseQuery(TObject *Sender, bool &CanClose)
{
  plying=false; brk=true; Application->ProcessMessages(); CanClose=true; delete plist; free(plems);
  if (!nodel && FileExists(ckf)) DeleteFile(ckf);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::BitBtn2Click(TObject *Sender)
{
  if (plist->Count<1) return;
  shuffleintarr(plems,plist->Count);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::zKnob1Change(TObject *Sender)
{
  static int olv=-1; int nmns,nscs;
  if (olv!=zKnob1->Value)
  {
    stp=zKnob1->Value; nmns=stp/60000; nscs=stp-nmns*60000;
    if (nmns>0) zKnob1->Hint="Step "+AnsiString(nmns)+"m "+AnsiString(nscs/1000)+"s";
    else zKnob1->Hint="Step "+mjfmtfl((double)nscs/1000.0)+"s";
    Application->HideHint(); Application->ActivateHint(Mouse->CursorPos); olv=stp;
  }
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormPaint(TObject *Sender)
{
  static bool clld=false;
  if (clld) return;
  clld=true; ckf=ChangeFileExt(ParamStr(0),".CPLY"); MediaPlayer1->Wait=false;
  if (!ParamStr(1).IsEmpty())
  {
    plist->Text=ParamStr(1);
    if (FileExists(ckf)) { plist->SaveToFile(ckf); nodel=true; Timer1->Enabled=true; return;}
    OpenDialog->InitialDir=ExtractFilePath(ParamStr(1)); cmdl=true; FileOpen(Sender);
  }
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Timer1Timer(TObject *Sender)
{
  Close();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Timer2Timer(TObject *Sender)
{
  if (plist->Count>0) dolabs();
  if (FileAge(ckf)!=ckt)
  {
    if (plying) { MediaPlayer1->Position=MediaPlayer1->Length; plying=false; brk=true;}
    else { plist->LoadFromFile(ckf); cmdl=true; FileOpen(Sender);}
  }
}
//---------------------------------------------------------------------------

-- 
Mark Jacobs
DK Computing
http://www.dkcomputing.co.uk
markj@criticalremovethisspuriousantispamstuff.co.uk

"Ron Sawyer" <rsawyer8128@aol.com> wrote in message news:3FCFB9A0.F2709BA@aol.com...
> Does anyone know of an MP3 Player VCL?  Does Direct Sound play MP3?
Technical Details
Message-ID: <4071717a@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!cyclone.bc.net!newsfeed2.telusplanet.net!newsfeed.telus.net!bigfeed.bellsouth.net!news.bellsouth.net!peer01.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3FCFB9A0.F2709BA@aol.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d0fc,432152316c0c9f0a
X-Google-Attributes: gid10d0fc,public
X-Google-ArrivalTime: 2004-04-05 08:09:02 PST
Reply-To: "Mark Jacobs" <markjremovethisspuriousantispamstuff@critical.co.uk>
From: "Mark Jacobs" <markjremovethisspuriousantispamstuff@critical.co.uk>
Newsgroups: borland.public.cppbuilder.multimedia
References: <3FCFB9A0.F2709BA@aol.com>
Subject: Re: MP3 VCL Player
Date: Mon, 5 Apr 2004 15:47:40 +0100
Lines: 176
Organization: DK Computing
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 81.144.157.8
Message-ID: <4071717a@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1081176442 81.144.157.8 (5 Apr 2004 07:47:22 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!cyclone.bc.net!newsfeed2.telusplanet.net!newsfeed.telus.net!bigfeed.bellsouth.net!news.bellsouth.net!peer01.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail