Article View: borland.public.cppbuilder.multimedia
Article #43Re: TMediaPlayer can't play MP3's
From: Remy Lebeau (TeamB)
Date: Tue, 16 May 2006 19:57
Date: Tue, 16 May 2006 19:57
105 lines
3892 bytes
3892 bytes
"Jonathan Benedicto" <invalid@nobody.com> wrote in message
news:4469cd34@newsgroups.borland.com...
> No, Windows Media Player uses DirectShow.
Which in itself is not that hard to use. I just recently wrote an app that
plays MP3s via DirectShow. It only takes a few lines of code to play a
file, ie:
#include <dshow.h>
IGraphBuilder *Graph = NULL;
IMediaControl *Control = NULL;
IMediaSeeking *Seeker = NULL
__fastcall TForm1::TForm1(TComponent *Owner)
: TForm(Owner)
{
::CoInitialize(NULL);
if( SUCCEEDED(::CoCreateInstance(CLSID_FilterGraph, NULL,
CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (LPVOID*)&Graph)) )
{
Graph->QueryInterface(IID_IMediaControl, (LPVOID*)&Control);
Graph->QueryInterface(IID_IMediaSeeking, (LPVOID*)&Seeker);
}
}
__fastcall TForm1::~TForm1()
{
if( Seeker )
Seeker->Release();
if( Control )
{
Control->Stop();
Control->Release();
}
if( Graph )
Graph->Release();
::CoUninitialize();
}
void __fastcall TForm1::OpenFileButtonClick(TObject *Sender)
{
if( Graph && Control )
{
if( OpenDialog1->Execute() )
{
Control->Stop();
RemoveFilters();
Graph->RenderFile(WideString(OpenDialog1->FileName), NULL);
}
}
}
void __fastcall TForm1::PlayFileButtonClick(TObject *Sender)
{
if( Control && Seeker )
{
REFERENCE_TIME rt = 0;
if( SUCCEEDED(Seeker->SetPositions(&rt,
AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning)) )
Control->Run();
}
}
void __fastcall TForm1::RemoveFilters()
{
IEnumFilters* pEnumFilters = NULL;
IBaseFilter* pFilter = NULL;
IEnumPins* pEnumPins = NULL;
IPin* pPin = NULL;
IPin* pOtherPin = NULL;
if( SUCCEEDED(Graph->EnumFilters(&pEnumFilters)) )
{
while( pEnumFilters->Next(1, &pFilter, NULL) == S_OK )
{
if( SUCCEEDED(pFilter->EnumPins(&pEnumPins)) )
{
while( pEnumPins->Next(1, &pPin, NULL) == S_OK )
{
if( pPin->ConnectedTo(&pOtherPin) == S_OK )
{
Graph->Disconnect(pPin);
Graph->Disconnect(pOtherPin);
pOtherPin->Release();
}
pPin->Release();
}
pEnumPins->Release();
}
Graph->RemoveFilter(pFilter);
pFilter->Release();
pEnumFilters->Reset();
}
pEnumFilters->Release();
}
}
Gambit
Technical Details
Message-ID:
<446a2f79$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<44695a5b$1@newsgroups.borland.com> <4469cd34@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10d0fc,e075f12cbf004ed2 X-Google-Attributes: gid10d0fc,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.multimedia References: <44695a5b$1@newsgroups.borland.com> <4469cd34@newsgroups.borland.com> Subject: Re: TMediaPlayer can't play MP3's Date: Tue, 16 May 2006 12:57:46 -0700 Lines: 107 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <446a2f79$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1147809657 68.69.17.41 (16 May 2006 13:00:57 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail