Board index » delphi » Launching windows default media player

Launching windows default media player

Hi!

I need to know how I launch the default videoplayer via COM from Delphi?
I have a filename of a specific filename I want the mediaplayer to play.
I must also know if no-one exists, so I can launch my own..

Does anyone know how to do this??

Thanks,
Kolbeinn Sigurjonsson

 

Re:Launching windows default media player


Hi,

Heres a routine I wrote to ascertain if "known" document types existed.  I use
this when I know it should return S_OK on success.  However, because it uses
the moniker to create the object , you are not 100% guaranteed to get back S_OK
due to no Monikers existing for the filetype.  In your case, you can be pretty
sure that the media support will return S_OK if Windows media is installed (I
have never had it fail on me).

function DefaultDocumentSupport(const Filename: string): HResult;
var
  pMKItem: IMoniker;
  pBCtx: IBindCtx;
  pUnknown: IUnknown;
begin
  Result := CreateFileMoniker(PWideChar(WideString(Filename)), pMKItem);
  if Result = S_OK then
  begin
    Result := CreateBindCtx(0, pBCtx);
    if Result = S_OK then
      Result := pMKItem.BindToObject(pBCtx, nil, IUnknown, pUnknown);
  end;
end;

Nick.

Quote
Kolbeinn Sigurjonsson <k...@net-album.com> wrote in message

news:80e2gl$scd15@forums.borland.com...
Quote
> Hi!

> I need to know how I launch the default videoplayer via COM from Delphi?
> I have a filename of a specific filename I want the mediaplayer to play.
> I must also know if no-one exists, so I can launch my own..

> Does anyone know how to do this??

> Thanks,
> Kolbeinn Sigurjonsson

Re:Launching windows default media player


BTW, the routine below is modified slightly to return the HResult instead of
the IUnknown - for simple mapping of filenames to Classes use GetClassFile.

Nick.

Quote
Nicholas Robinson <NicholasRobin...@yahoo.co.uk> wrote in message

news:80ee12$3b12@forums.borland.com...
Quote
> Hi,

> Heres a routine I wrote to ascertain if "known" document types existed.  I
use
> this when I know it should return S_OK on success.  However, because it uses
> the moniker to create the object , you are not 100% guaranteed to get back
S_OK
> due to no Monikers existing for the filetype.  In your case, you can be
pretty
> sure that the media support will return S_OK if Windows media is installed (I
> have never had it fail on me).

> function DefaultDocumentSupport(const Filename: string): HResult;
> var
>   pMKItem: IMoniker;
>   pBCtx: IBindCtx;
>   pUnknown: IUnknown;
> begin
>   Result := CreateFileMoniker(PWideChar(WideString(Filename)), pMKItem);
>   if Result = S_OK then
>   begin
>     Result := CreateBindCtx(0, pBCtx);
>     if Result = S_OK then
>       Result := pMKItem.BindToObject(pBCtx, nil, IUnknown, pUnknown);
>   end;
> end;

> Nick.

> Kolbeinn Sigurjonsson <k...@net-album.com> wrote in message
> news:80e2gl$scd15@forums.borland.com...
> > Hi!

> > I need to know how I launch the default videoplayer via COM from Delphi?
> > I have a filename of a specific filename I want the mediaplayer to play.
> > I must also know if no-one exists, so I can launch my own..

> > Does anyone know how to do this??

> > Thanks,
> > Kolbeinn Sigurjonsson

Re:Launching windows default media player


Hi (again!),

Try first calling GetClassFile.  If something valid comes back you can then
execute the registered application using the ShellExecute API.  If GetClassFile
fails, as far as you are aware, you need to implement your own.

Nick.

Quote
Kolbeinn Sigurjonsson <k...@net-album.com> wrote in message

news:80e2gl$scd15@forums.borland.com...
Quote
> Hi!

> I need to know how I launch the default videoplayer via COM from Delphi?
> I have a filename of a specific filename I want the mediaplayer to play.
> I must also know if no-one exists, so I can launch my own..

> Does anyone know how to do this??

> Thanks,
> Kolbeinn Sigurjonsson

Re:Launching windows default media player


Just the ShellExcute, it will fire up the player that is registered to run
the extention..
Quote
Kolbeinn Sigurjonsson wrote:
> Hi!

> I need to know how I launch the default videoplayer via COM from Delphi?
> I have a filename of a specific filename I want the mediaplayer to play.
> I must also know if no-one exists, so I can launch my own..

> Does anyone know how to do this??

> Thanks,
> Kolbeinn Sigurjonsson

Other Threads