Перейти к содержанию
Fire Monkey от А до Я

Лидеры

Популярный контент

Показан контент с высокой репутацией 17.03.2021 во всех областях

  1. 1 балл
  2. OnePeople

    [Android] Воспроизводить аудио

    По поведению на различных прошивках я не могу вам ни чего сказать вообще не думаю что это связанно с версией андроида, а связанно с прошивкой вендора. Выдернул из рабочего проекта, строго не пинать, за корявость) 1. type {$IFDEF ANDROID} TMyAudioFocusChangeListener = class; {$ENDIF} TForm1 = class(TForm) 2. private { Private declarations } {$IFDEF ANDROID} afChangeListener: TMyAudioFocusChangeListener; 3. public procedure onAudioFocusChange(focusChange: Integer); end; TAudioFocusChangeEvent = procedure(focusChange: Integer) of object; TMyAudioFocusChangeListener = class(TJavaLocal, JAudioManager_OnAudioFocusChangeListener) private [weak] FParent : TForm1; FOnAudioFocusChanged: TAudioFocusChangeEvent; public constructor Create(AParent : TForm1); property OnAudioFocusChanged: TAudioFocusChangeEvent read FOnAudioFocusChanged write FOnAudioFocusChanged; Destructor Destroy; Override; procedure onAudioFocusChange(focusChange: Integer); cdecl; end; 4. constructor TMyAudioFocusChangeListener.Create; begin inherited Create; FParent := AParent; end; destructor TMyAudioFocusChangeListener.Destroy; begin inherited; end; procedure TMyAudioFocusChangeListener.onAudioFocusChange(focusChange: Integer); begin if Assigned(FOnAudioFocusChanged) then begin FOnAudioFocusChanged(focusChange); end; FParent.onAudioFocusChange(focusChange); end; procedure TForm1.onAudioFocusChange(focusChange: Integer); begin Form1.Memo2.Lines.Add('focus change:'+focusChange.ToString); if (focusChange=TJaudioManager.JavaClass.AUDIOFOCUS_LOSS) then begin MusicControl.AudioFocus:=false; case MusicControl.MusicType of TMusicType.Music: if MusicControl.Music.MusicState=TMusicState.Play then begin MusicPlayPause; exit; end; TMusicType.Radio: if MusicControl.Radio.MusicState=TMusicState.Play then begin RadioPlayPause; exit; end; end; end; end; 5. procedure TForm1.GetAudioFocus; begin // {$IFDEF ANDROID} CallinUIThread(procedure var AudioFocusRequest: JAudioFocusRequest; playbackAttributes: JAudioAttributes; afHandler: JHandler; res: integer; begin afChangeListener:=TMyAudioFocusChangeListener.Create(Self); afHandler:= TJHandler.Create; playbackAttributes := TJAudioAttributes_Builder.Create .setUsage(TJAudioAttributes.JavaClass.USAGE_MEDIA) .setContentType(TJAudioAttributes.JavaClass.CONTENT_TYPE_MUSIC) .build(); AudioFocusRequest:=TJAudioFocusRequest_Builder(TJAudioManager.JavaClass.AUDIOFOCUS_GAIN).Create .setAudioAttributes(playbackAttributes) .setAcceptsDelayedFocusGain(true) .setOnAudioFocusChangeListener(afChangeListener, afHandler) .build(); res:=FAudioManager.requestAudioFocus(AudioFocusRequest); if res = TJAudioManager.JavaClass.AUDIOFOCUS_REQUEST_DELAYED then LogCAAdd('AUDIOFOCUS_REQUEST_DELAYED') else if res = TJAudioManager.JavaClass.AUDIOFOCUS_REQUEST_GRANTED then begin MusicControl.AudioFocus:=true; LogCAAdd('AUDIOFOCUS_REQUEST_GRANTED'); end else if res = TJAudioManager.JavaClass.AUDIOFOCUS_REQUEST_DELAYED then LogCAAdd('AUDIOFOCUS_REQUEST_DELAYED'); end ); {$ENDIF} end; P.S. Для android 8 выше! для поддержки ранешних версий Android нужно немного дописать
    1 балл
  3. gonzales

    поломались ПУШи в 10.4

    Нашел причину, В недрах класса TPushService TPushService = class abstract public type TPropPair = TPair<string, string>; TPropArray = TArray<TPropPair>; // commonly used names TServiceNames = record public const GCM = 'gcm'; // deprecated 'Is not available anymore. Please use FCM instead'; // Google cloud messaging FCM = 'fcm'; // Google Firebase cloud messaging APS = 'aps'; // Apple end; Соответственно нужно исправить FPushService := TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.GCM); на FPushService := TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.FCM); Все работает
    1 балл
Эта таблица лидеров рассчитана в Москва/GMT+03:00
×
×
  • Создать...