I prefer to use Windows Media Player for my movies, music and DVDs, but this is not a preference that is shared by other users, so my application must be able to automatically and transparently determine which program must be used to launch movie files.
For example, if I double-click a icon in my program, it will determine that the file "O:\Movies\Sci-Fi\Star Trek 11\Star Trek 11.avi" needs to be played. If a single file must be opened, I can easily use ShellExecute, because Windows itself will take care of determining the appropriately associated program with which to open the file.
Code:
ShellExecute(Application.Handle, nil, pChar(AFilename), nil, nil, SW_SHOW);
But the above does not work if more than one video file needs to be opened. For that, ShellExecute needs to know the full path name of the program to execute, and the appropriate parameters that needs to be passed to it. The following is a code extract from my application:
Code:
procedure TFormMainMovies.PlayMovies(AFileList:TStringList);
var
BufferSize : DWORD;
ExpandedCmd : string;
MediaPlayer : string;
ExeReturn:HINST;
VideoFiles:TStringList;
Parse : Integer;
begin
{}
MediaPlayer := '%ProgramFiles(x86)%\Windows Media Player\wmplayer.exe';
ExpandedCmd := '';
BufferSize := ExpandEnvironmentStrings(pChar(MediaPlayer), pChar(ExpandedCmd), 0);
if BufferSize > 0 then
begin
VideoFiles := TStringList.Create;
try
{}
ExpandedCmd := StringOfChar(#0, BufferSize);
BufferSize := ExpandEnvironmentStrings(pChar(MediaPlayer), pChar(ExpandedCmd), Length(ExpandedCmd));
if BufferSize <= 0 then
begin
{could not expand media player environment string}
end
else
begin
{When passing multiple files to wmplayer, a CRLF seperated list must be passed to ShellExecute}
VideoFiles.Assign(AFileList);
for Parse := 0 to VideoFiles.Count - 1 do
VideoFiles.Strings[Parse] := #34 + Trim(VideoFiles.Strings[Parse]) + #34;
{}
ExeReturn := ShellExecute(Application.Handle, nil, pchar(ExpandedCmd), pChar('/fullscreen '+VideoFiles.Text), nil, SW_SHOW);
if not (ExeReturn > 32) then
begin
{ShellExecute returned an error}
end;
end;
finally
FreeAndNil(VideoFiles);
end;
end;
end; The question I'm asking is this:
Given a particular file type (AVI, MPG, DIVX), how do I determine the fully qualified path to the exe that opens the file? Is there a (simple) API call that I can use to do this, or do I need to read the registry manually?
Also, my program currently only searches for AVI, MPG, MPEG and DIVX file types. In relation to videos, what other file extensions should I be looking for?