Advertisement
stonemaster

Inno Media Player

Sep 27th, 2015
3,122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [Setup]
  2. AppName=Media Player Project
  3. AppVersion=1.0
  4. DefaultDirName={pf}\Media Player Project
  5.  
  6. [Files]
  7. Source: "MediaPlayer.dll"; Flags: dontcopy
  8.  
  9. [Code]
  10. const
  11.   EC_COMPLETE = $01;
  12.  
  13. type
  14.   TDirectShowEventProc = procedure(EventCode, Param1, Param2: Integer);
  15.  
  16. function DSGetLastError(var ErrorText: WideString): HRESULT;
  17.   external 'DSGetLastError@files:mediaplayer.dll stdcall';
  18. function DSPlayMediaFile: Boolean;
  19.   external 'DSPlayMediaFile@files:mediaplayer.dll stdcall';
  20. function DSStopMediaPlay: Boolean;
  21.   external 'DSStopMediaPlay@files:mediaplayer.dll stdcall';
  22. function DSSetVolume(Value: LongInt): Boolean;
  23.   external 'DSSetVolume@files:mediaplayer.dll stdcall';
  24. function DSSetBalance(Value: LongInt): Boolean;
  25.   external 'DSSetBalance@files:mediaplayer.dll stdcall';
  26. function DSInitializeAudioFile(FileName: WideString; CallbackProc: TDirectShowEventProc):
  27.   Boolean; external 'DSInitializeAudioFile@files:mediaplayer.dll stdcall';
  28. function DSInitializeVideoFile(FileName: WideString; WindowHandle: HWND; var Width,
  29.   Height: Integer; CallbackProc: TDirectShowEventProc): Boolean;
  30.   external 'DSInitializeVideoFile@files:mediaplayer.dll stdcall';
  31.  
  32. var
  33.   VideoForm: TSetupForm;
  34.   AudioPage: TWizardPage;
  35.   VideoPage: TWizardPage;
  36.   VideoPanel: TPanel;
  37.  
  38. procedure OnMediaPlayerEvent(EventCode, Param1, Param2: Integer);
  39. begin
  40.   if EventCode = EC_COMPLETE then
  41.     VideoForm.Close;
  42. end;
  43.  
  44. procedure OnVideoFormShow(Sender: TObject);
  45. var
  46.   ErrorCode: HRESULT;
  47.   ErrorText: WideString;
  48.   Width, Height: Integer;
  49. begin
  50.   if DSInitializeVideoFile('c:\Video.avi', VideoForm.Handle, Width,
  51.     Height, @OnMediaPlayerEvent) then
  52.   begin
  53.     VideoForm.ClientWidth := Width;
  54.     VideoForm.ClientHeight := Height;
  55.     DSPlayMediaFile;
  56.   end
  57.   else
  58.   begin
  59.     ErrorCode := DSGetLastError(ErrorText);
  60.     MsgBox('TDirectShowPlayer error: ' + IntToStr(ErrorCode) + '; ' +
  61.       ErrorText, mbError, MB_OK);
  62.   end;
  63. end;
  64.  
  65. procedure OnVideoFormClose(Sender: TObject; var Action: TCloseAction);
  66. begin
  67.   DSStopMediaPlay;
  68. end;
  69.  
  70. procedure InitializeWizard;
  71. begin
  72.   VideoForm := CreateCustomForm;
  73.   VideoForm.Position := poScreenCenter;
  74.   VideoForm.OnShow := @OnVideoFormShow;
  75.   VideoForm.OnClose := @OnVideoFormClose;
  76.   VideoForm.FormStyle := fsStayOnTop;
  77.   VideoForm.Caption := 'Popup Video Window';
  78.   VideoForm.ShowModal;
  79.  
  80.   VideoPage := CreateCustomPage(wpWelcome, 'Video Page', 'Embedded video');
  81.   VideoPanel := TPanel.Create(WizardForm);
  82.   VideoPanel.Parent := VideoPage.Surface;
  83.   VideoPanel.BevelOuter := bvNone;
  84.   VideoPanel.Width := Round(VideoPage.Surface.ClientWidth / 1.5);
  85.   VideoPanel.Height := Round(VideoPage.Surface.ClientHeight / 1.5);
  86.   VideoPanel.Left := (VideoPage.Surface.ClientWidth - VideoPanel.Width) div 2;
  87.   VideoPanel.Top := (VideoPage.Surface.ClientHeight - VideoPanel.Height) div 2;
  88.  
  89.   AudioPage := CreateCustomPage(VideoPage.ID, 'Audio Page', 'Embedded audio');
  90. end;
  91.  
  92. procedure OnEmbeddedMediaPlayerEvent(EventCode, Param1, Param2: Integer);
  93. begin
  94.   if EventCode = EC_COMPLETE then
  95.     MsgBox('Playback is done!', mbInformation, MB_OK);
  96. end;
  97.  
  98. procedure CurPageChanged(CurPageID: Integer);
  99. var
  100.   ErrorCode: HRESULT;
  101.   ErrorText: WideString;
  102.   Width, Height: Integer;
  103. begin
  104.   case CurPageID of
  105.     VideoPage.ID:
  106.     begin
  107.       Width := VideoPanel.ClientWidth;
  108.       Height := VideoPanel.ClientHeight;
  109.       WizardForm.InnerPage.Color := clBlack;
  110.       if DSInitializeVideoFile('c:\Video.avi', VideoPanel.Handle, Width, Height,
  111.         @OnEmbeddedMediaPlayerEvent)
  112.       then
  113.         DSPlayMediaFile
  114.       else
  115.       begin
  116.         ErrorCode := DSGetLastError(ErrorText);
  117.         MsgBox('TDirectShowPlayer error: ' + IntToStr(ErrorCode) + '; ' +
  118.           ErrorText, mbError, MB_OK);
  119.       end;
  120.     end;
  121.     AudioPage.ID:
  122.     begin
  123.       WizardForm.InnerPage.Color := clBtnFace;
  124.       if DSInitializeAudioFile('c:\Audio.mp3', @OnEmbeddedMediaPlayerEvent) then
  125.       begin
  126.         DSSetVolume(-2500);
  127.         DSPlayMediaFile;
  128.       end
  129.       else
  130.       begin
  131.         ErrorCode := DSGetLastError(ErrorText);
  132.         MsgBox('TDirectShowPlayer error: ' + IntToStr(ErrorCode) + '; ' +
  133.           ErrorText, mbError, MB_OK);
  134.       end;
  135.     end
  136.   else
  137.     begin
  138.       DSStopMediaPlay;
  139.       WizardForm.InnerPage.Color := clBtnFace;
  140.     end;
  141.   end;
  142. end;
  143.  
  144. procedure DeinitializeSetup;
  145. begin
  146.   DSStopMediaPlay;
  147. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement