Search code examples
androiddelphifiremonkey

Mute/stop video running in background (Delphi - Android App)


I have an application in Delphi that plays video. When I open another application, but blank the screen, I hear the Video sound all the time. How can I detect that the screen has been blanked, or there has been a switch to another application ?


Solution

  • I found a solution.

    uses FMX.Platform;
    
    procedure TMyForm.FormCreate(Sender: TObject);
    var
    AppEventSvc:IFMXApplicationEventService;
    begin
    if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService,IInterface(AppEventSvc)) then
    begin
    AppEventSvc.SetApplicationEventHandler(AppEvent);
    end;
    end;
    
    function TMyForm.AppEvent(AAppEvent:TApplicationEvent;AContext:TObject):Boolean;
    begin
    if AAppEvent=TApplicationEvent.WillTerminate then
    begin
    // Do soomething
    end;
    Result:=True;
    end;