Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Jata to Delphi



Permlink Replies: 26 - Last Post: Nov 2, 2015 12:45 PM Last Post By: Remy Lebeau (Te...
Carlos Phelippe

Posts: 39
Registered: 9/14/15
Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 6, 2015 9:18 AM
Hello!

I need to covert this code Java to Delphi:

http://developer.android.com/training/managing-audio/audio-focus.html

How?
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 7, 2015 1:44 PM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Am 06.09.2015 um 18:18 schrieb Carlos Phelippe:
Hello!

I need to covert this code Java to Delphi:

http://developer.android.com/training/managing-audio/audio-focus.html

How?

Hello,

first you need a translation of that Android Java API.
Afaik in the buin directory there's some tool for helping with that.

Greetings

Markus
Peter Philippa

Posts: 4
Registered: 11/5/99
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 8, 2015 3:53 PM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos Phelippe wrote:
Hello!

I need to covert this code Java to Delphi:

http://developer.android.com/training/managing-audio/audio-focus.html

How?

You shall need to use the Java2OP command line tool that has accompanied the trial versions of RadStudio. Look at the readme.txt file for some info on how to use the utility. Though this posting:

http://www.fmxexpress.com/utility-to-generate-java-android-class-and-jar-file-interfaces-for-delphi-xe5-firemonkey/

actually relates to a different conversion tool, the article may put you on the path of success. Cheers, Peter
Peter Philippa

Posts: 4
Registered: 11/5/99
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 8, 2015 4:06 PM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos Phelippe wrote:
Hello!

I need to covert this code Java to Delphi:

http://developer.android.com/training/managing-audio/audio-focus.html

How?

Further to may earlier reply, you may like to also have a look at this article - which gives links to other articles which may help:

http://www.fmxexpress.com/create-delphi-interface-from-android-jar-file/

Cheers, Peter
Carlos Phelippe

Posts: 39
Registered: 9/14/15
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 11, 2015 9:55 AM   in response to: Peter Philippa in response to: Peter Philippa
Peter Philippa wrote:
Carlos Phelippe wrote:
Hello!

I need to covert this code Java to Delphi:

http://developer.android.com/training/managing-audio/audio-focus.html

How?

Further to may earlier reply, you may like to also have a look at this article - which gives links to other articles which may help:

http://www.fmxexpress.com/create-delphi-interface-from-android-jar-file/

Cheers, Peter

Hello!

Hello!
I am trying to do:
http://developer.android.com/training/managing-audio/audio-focus.html

I have this:

C:\Program Files (x86)\Embarcadero\Studio\16.0\source\rtl\android\Androidapi.JNI.Media.pas

  JAudioManager_OnAudioFocusChangeListenerClass = interface(IJavaClass)
    ['{D79C0846-0031-48D5-9EB0-A995A3D034A2}']
  end;
 
  [JavaSignature('android/media/AudioManager$OnAudioFocusChangeListener')]
  JAudioManager_OnAudioFocusChangeListener = interface(IJavaInstance)
    ['{F6FE80F4-5596-4E41-B718-BFEEEDBFAE47}']
    procedure onAudioFocusChange(focusChange: Integer); cdecl;
  end;
  TJAudioManager_OnAudioFocusChangeListener = class(TJavaGenericImport<JAudioManager_OnAudioFocusChangeListenerClass, JAudioManager_OnAudioFocusChangeListener>) end;
 


I need to use this to know when my app has audio focus.

I am doing so:

var
    myAudioMgr : JAudioManager;
    _aa : JAudioManager_OnAudioFocusChangeListener;

....
Form Create:
   obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
   myAudioMgr :=  TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
 
  myAudioMgr.requestAudioFocus(_aa,
                               TJAudioManager.JavaClass.STREAM_MUSIC,
                               TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
 
 
     _aa.myOnAudioFocusChange := self.onMyAudioFocusChange;
 
....
procedure TForm1.onMyAudioFocusChange(focusChange: System.Integer);
begin
  Log.Add(focusChange); 
end;
 


I have error when compile this line:
_aa.myOnAudioFocusChange := self.onMyAudioFocusChange;

[DCC Error] uMain.pas(205): E2035 Not enough actual parameters

Carlos Phelippe

Posts: 39
Registered: 9/14/15
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 21, 2015 3:35 AM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos Phelippe wrote:
Peter Philippa wrote:
Carlos Phelippe wrote:
Hello!

I need to covert this code Java to Delphi:

http://developer.android.com/training/managing-audio/audio-focus.html

How?

Further to may earlier reply, you may like to also have a look at this article - which gives links to other articles which may help:

http://www.fmxexpress.com/create-delphi-interface-from-android-jar-file/

Cheers, Peter

Hello!

Hello!
I am trying to do:
http://developer.android.com/training/managing-audio/audio-focus.html

I have this:

C:\Program Files (x86)\Embarcadero\Studio\16.0\source\rtl\android\Androidapi.JNI.Media.pas

  JAudioManager_OnAudioFocusChangeListenerClass = interface(IJavaClass)
    ['{D79C0846-0031-48D5-9EB0-A995A3D034A2}']
  end;
 
  [JavaSignature('android/media/AudioManager$OnAudioFocusChangeListener')]
  JAudioManager_OnAudioFocusChangeListener = interface(IJavaInstance)
    ['{F6FE80F4-5596-4E41-B718-BFEEEDBFAE47}']
    procedure onAudioFocusChange(focusChange: Integer); cdecl;
  end;
  TJAudioManager_OnAudioFocusChangeListener = class(TJavaGenericImport<JAudioManager_OnAudioFocusChangeListenerClass, JAudioManager_OnAudioFocusChangeListener>) end;
 


I need to use this to know when my app has audio focus.

I am doing so:

var
    myAudioMgr : JAudioManager;
    _aa : JAudioManager_OnAudioFocusChangeListener;

....
Form Create:
   obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
   myAudioMgr :=  TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
 
  myAudioMgr.requestAudioFocus(_aa,
                               TJAudioManager.JavaClass.STREAM_MUSIC,
                               TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
 
 
     _aa.myOnAudioFocusChange := self.onMyAudioFocusChange;
 
....
procedure TForm1.onMyAudioFocusChange(focusChange: System.Integer);
begin
  Log.Add(focusChange); 
end;
 


I have error when compile this line:
_aa.myOnAudioFocusChange := self.onMyAudioFocusChange;

[DCC Error] uMain.pas(205): E2035 Not enough actual parameters


up :(
Carlos Phelippe

Posts: 39
Registered: 9/14/15
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 13, 2015 11:49 AM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos Phelippe wrote:
Carlos Phelippe wrote:
Peter Philippa wrote:
Carlos Phelippe wrote:
Hello!

I need to covert this code Java to Delphi:

http://developer.android.com/training/managing-audio/audio-focus.html

How?

Further to may earlier reply, you may like to also have a look at this article - which gives links to other articles which may help:

http://www.fmxexpress.com/create-delphi-interface-from-android-jar-file/

Cheers, Peter

Hello!

Hello!
I am trying to do:
http://developer.android.com/training/managing-audio/audio-focus.html

I have this:

C:\Program Files (x86)\Embarcadero\Studio\16.0\source\rtl\android\Androidapi.JNI.Media.pas

  JAudioManager_OnAudioFocusChangeListenerClass = interface(IJavaClass)
    ['{D79C0846-0031-48D5-9EB0-A995A3D034A2}']
  end;
 
  [JavaSignature('android/media/AudioManager$OnAudioFocusChangeListener')]
  JAudioManager_OnAudioFocusChangeListener = interface(IJavaInstance)
    ['{F6FE80F4-5596-4E41-B718-BFEEEDBFAE47}']
    procedure onAudioFocusChange(focusChange: Integer); cdecl;
  end;
  TJAudioManager_OnAudioFocusChangeListener = class(TJavaGenericImport<JAudioManager_OnAudioFocusChangeListenerClass, JAudioManager_OnAudioFocusChangeListener>) end;
 


I need to use this to know when my app has audio focus.

I am doing so:

var
    myAudioMgr : JAudioManager;
    _aa : JAudioManager_OnAudioFocusChangeListener;

....
Form Create:
   obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
   myAudioMgr :=  TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
 
  myAudioMgr.requestAudioFocus(_aa,
                               TJAudioManager.JavaClass.STREAM_MUSIC,
                               TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
 
 
     _aa.myOnAudioFocusChange := self.onMyAudioFocusChange;
 
....
procedure TForm1.onMyAudioFocusChange(focusChange: System.Integer);
begin
  Log.Add(focusChange); 
end;
 


I have error when compile this line:
_aa.myOnAudioFocusChange := self.onMyAudioFocusChange;

[DCC Error] uMain.pas(205): E2035 Not enough actual parameters


up :(

Up again.
Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 15, 2015 7:38 AM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos Phelippe wrote:

I have error when compile this line:
_aa.myOnAudioFocusChange := self.onMyAudioFocusChange;

[DCC Error] uMain.pas(205): E2035 Not enough actual parameters


up :(

Unfortunately from your code snippet it's hard to tell what you're
trying to achieve. I cannot find what is myOnAudioFocusChange (it's not
part of Androidapi.JNI.Media). My guess is that you're trying to assign
a method to another method.

But this is a wild guess.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 15, 2015 12:56 PM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos wrote:

I need to use this to know when my app has audio focus.

You are supposed to create a class that implements the AudioManager.OnAudioFocusChangeListener
interface (JAudioManager_OnAudioFocusChangeListener in Delphi), overriding
its onAudioFocusChange() method, and then pass an instance of that class
to the AudioManager.requestAudioFocus() method. You are not doing that.
But you already knew about that, didn't you? Based on a discussion I found
on the Un4seen forum:

http://www.un4seen.com/forum/?topic=16692.msg116779

So, something like the following should work:

type
  TAudioFocusChangeEvent = procedure(focusChange: Integer) of object;
 
  TMyAudioFocusChangeListener = class(TJavaLocal, JAudioManager_OnAudioFocusChangeListener)
  private
    FOnAudioFocusChanged: TAudioFocusChangeEvent;
  public
    procedure onAudioFocusChange(focusChange: Integer); cdecl;
    property OnAudioFocusChanged: TAudioFocusChangeEvent read FOnAudioFocusChanged 
write FOnAudioFocusChanged;
  end;
 
procedure TMyAudioFocusChangeListener.onAudioFocusChange(focusChange: Integer);
begin
  if Assigned(FOnAudioFocusChanged) then
    FOnAudioFocusChanged(focusChange);
end;
 
procedure TForm1.FormCreate(Sender: TObject);
var
  obj: JObject;
  myAudioMgr : JAudioManager;
  myListener : TMyAudioFocusChangeListener;
begin
  obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
  myAudioMgr := TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
  myListener := TMyAudioFocusChangeListener.Create;
  myListener.OnAudioFocusChanged := onMyAudioFocusChange;
 
  myAudioMgr.requestAudioFocus(myListener, TJAudioManager.JavaClass.STREAM_MUSIC, 
TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
end;
 
procedure TForm1.onMyAudioFocusChange(focusChange: Integer);
begin
  Log.Add(focusChange); 
end;


--
Remy Lebeau (TeamB)
Carlos Phelippe

Posts: 39
Registered: 9/14/15
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2015 9:05 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Carlos wrote:

I need to use this to know when my app has audio focus.

You are supposed to create a class that implements the AudioManager.OnAudioFocusChangeListener
interface (JAudioManager_OnAudioFocusChangeListener in Delphi), overriding
its onAudioFocusChange() method, and then pass an instance of that class
to the AudioManager.requestAudioFocus() method. You are not doing that.
But you already knew about that, didn't you? Based on a discussion I found
on the Un4seen forum:

http://www.un4seen.com/forum/?topic=16692.msg116779

So, something like the following should work:

type
  TAudioFocusChangeEvent = procedure(focusChange: Integer) of object;
 
  TMyAudioFocusChangeListener = class(TJavaLocal, JAudioManager_OnAudioFocusChangeListener)
  private
    FOnAudioFocusChanged: TAudioFocusChangeEvent;
  public
    procedure onAudioFocusChange(focusChange: Integer); cdecl;
    property OnAudioFocusChanged: TAudioFocusChangeEvent read FOnAudioFocusChanged 
write FOnAudioFocusChanged;
  end;
 
procedure TMyAudioFocusChangeListener.onAudioFocusChange(focusChange: Integer);
begin
  if Assigned(FOnAudioFocusChanged) then
    FOnAudioFocusChanged(focusChange);
end;
 
procedure TForm1.FormCreate(Sender: TObject);
var
  obj: JObject;
  myAudioMgr : JAudioManager;
  myListener : TMyAudioFocusChangeListener;
begin
  obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
  myAudioMgr := TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
  myListener := TMyAudioFocusChangeListener.Create;
  myListener.OnAudioFocusChanged := onMyAudioFocusChange;
 
  myAudioMgr.requestAudioFocus(myListener, TJAudioManager.JavaClass.STREAM_MUSIC, 
TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
end;
 
procedure TForm1.onMyAudioFocusChange(focusChange: Integer);
begin
  Log.Add(focusChange); 
end;


--
Remy Lebeau (TeamB)

Hello!

I did. But, this

 procedure TForm1.onMyAudioFocusChange(focusChange: Integer);
 begin
   Log.Add(focusChange); 
 end;


Never is call. :( :(
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2015 10:15 AM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos wrote:

I did. But, this

procedure TForm1.onMyAudioFocusChange(focusChange: Integer);
begin
Log.Add(focusChange);
end;


Never is call. :( :(

Is requestAudioFocus() returning 1 (AUDIOFOCUS_REQUEST_GRANTED) or 0 (AUDIOFOCUS_REQUEST_FAILED)?

--
Remy Lebeau (TeamB)
Carlos Phelippe

Posts: 39
Registered: 9/14/15
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2015 11:41 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Carlos wrote:

I did. But, this

procedure TForm1.onMyAudioFocusChange(focusChange: Integer);
begin
Log.Add(focusChange);
end;


Never is call. :( :(

Is requestAudioFocus() returning 1 (AUDIOFOCUS_REQUEST_GRANTED) or 0 (AUDIOFOCUS_REQUEST_FAILED)?

--
Remy Lebeau (TeamB)

Hello!

I run my app. I request audio focus. For sample, if I have 'vlc android player' running and start my app 'vlc android player' stop. So AUDIOFOCUS_REQUEST_GRANTED works correctly. Now, my app is running and I start a music file (mp3) using 'vlc android player' my app needs to know when 'vlc android player' request audio focus.... but .onMyAudioFocusChange(focusChange: Integer); never is call.

Sorry, but you undertood?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2015 1:23 PM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos wrote:

I run my app. I request audio focus. For sample, if I have 'vlc
android player' running and start my app 'vlc android player' stop.
So AUDIOFOCUS_REQUEST_GRANTED works correctly.

That is not what I asked you. But based on this info, I will have to assume
that "yes, requestAudioFocus() returns 1".

Now, my app is running and I start a music file (mp3) using
'vlc android player' my app needs to know when 'vlc android player'
request audio focus....

Assuming it does, which well-behaved apps should be doing...

but .onMyAudioFocusChange(focusChange: Integer); never is call.

Then you probably need to file a QP ticket with Embarcadero and ask them
about it.

FireMonkey implements Android listeners internally, such as in the Androidapi.JNI.ApkExpansion
and FMX.Advertising.Android units. They use the same technique described
in my earlier example, however the Advertising listener has one one additional
step - after the listener object is created, instead of passing it directly
to Android, Embarcadero wraps it in an adapter class:

FAdViewListener := TAdViewListener.Create(Self);
FJAd.setAdListener(TJAdListenerAdapter.JavaClass.init(FAdViewListener));


That adapter is implemented inside of a private Embarcadero library that
we don't have the source for, so I don't know what that adapter is actually
doing. On the other hand, the ApkExpansion listener has no adapter, it is
passed as-is to Android, just like in my example. So, I have to assume that
Delphi-written listeners CAN be passed to Android.

I suspect the more important issue is ARC reference counting on mobile platforms.
In my earlier example, and in your original code, the listener object has
no active reference for the entire lifetime of the TForm. So I would suggest
adding that (you need it anyway so you can abandon audio focus when you are
not playing audio):

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    ...
  private
    myAudioMgr : JAudioManager;
    myListener : TMyAudioFocusChangeListener;
    procedure onMyAudioFocusChange(focusChange: Integer);
    ...
  end;
 
procedure TForm1.FormCreate(Sender: TObject);
var
  obj: JObject;
begin
  obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
  myAudioMgr := TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
  myListener := TMyAudioFocusChangeListener.Create;
  myListener.OnAudioFocusChanged := onMyAudioFocusChange;
 
  myAudioMgr.requestAudioFocus(myListener, TJAudioManager.JavaClass.STREAM_MUSIC, 
TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
  myAudioMgr.abandonAudioFocus(myListener);
  myListener := nil;
  myAudioMgr := nil;
end;


Alternatively, it might be possible (I am not entirely sure) to have the
TForm class itself implement the listener interface, instead of using a separate
class:

type
  TForm1 = class(TForm, JAudioManager_OnAudioFocusChangeListener)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    ...
  private
    myAudioMgr : JAudioManager;
    ...
  public
    procedure onAudioFocusChange(focusChange: Integer); cdecl;
  end;
 
procedure TForm1.FormCreate(Sender: TObject);
var
  obj: JObject;
begin
  obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
  myAudioMgr := TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
  myAudioMgr.requestAudioFocus(Self, TJAudioManager.JavaClass.STREAM_MUSIC, 
TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
  myAudioMgr.abandonAudioFocus(Self);
  myAudioMgr := nil;
end;
 
procedure TForm1.onAudioFocusChange(focusChange: Integer);
begin
  Log.Add(focusChange); 
end;


See if either approach makes any difference.

--
Remy Lebeau (TeamB)
Carlos Phelippe

Posts: 39
Registered: 9/14/15
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2015 5:40 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Carlos wrote:

I run my app. I request audio focus. For sample, if I have 'vlc
android player' running and start my app 'vlc android player' stop.
So AUDIOFOCUS_REQUEST_GRANTED works correctly.

That is not what I asked you. But based on this info, I will have to assume
that "yes, requestAudioFocus() returns 1".

Now, my app is running and I start a music file (mp3) using
'vlc android player' my app needs to know when 'vlc android player'
request audio focus....

Assuming it does, which well-behaved apps should be doing...

but .onMyAudioFocusChange(focusChange: Integer); never is call.

Then you probably need to file a QP ticket with Embarcadero and ask them
about it.

FireMonkey implements Android listeners internally, such as in the Androidapi.JNI.ApkExpansion
and FMX.Advertising.Android units. They use the same technique described
in my earlier example, however the Advertising listener has one one additional
step - after the listener object is created, instead of passing it directly
to Android, Embarcadero wraps it in an adapter class:

FAdViewListener := TAdViewListener.Create(Self);
FJAd.setAdListener(TJAdListenerAdapter.JavaClass.init(FAdViewListener));


That adapter is implemented inside of a private Embarcadero library that
we don't have the source for, so I don't know what that adapter is actually
doing. On the other hand, the ApkExpansion listener has no adapter, it is
passed as-is to Android, just like in my example. So, I have to assume that
Delphi-written listeners CAN be passed to Android.

I suspect the more important issue is ARC reference counting on mobile platforms.
In my earlier example, and in your original code, the listener object has
no active reference for the entire lifetime of the TForm. So I would suggest
adding that (you need it anyway so you can abandon audio focus when you are
not playing audio):

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    ...
  private
    myAudioMgr : JAudioManager;
    myListener : TMyAudioFocusChangeListener;
    procedure onMyAudioFocusChange(focusChange: Integer);
    ...
  end;
 
procedure TForm1.FormCreate(Sender: TObject);
var
  obj: JObject;
begin
  obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
  myAudioMgr := TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
  myListener := TMyAudioFocusChangeListener.Create;
  myListener.OnAudioFocusChanged := onMyAudioFocusChange;
 
  myAudioMgr.requestAudioFocus(myListener, TJAudioManager.JavaClass.STREAM_MUSIC, 
TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
  myAudioMgr.abandonAudioFocus(myListener);
  myListener := nil;
  myAudioMgr := nil;
end;


Alternatively, it might be possible (I am not entirely sure) to have the
TForm class itself implement the listener interface, instead of using a separate
class:

type
  TForm1 = class(TForm, JAudioManager_OnAudioFocusChangeListener)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    ...
  private
    myAudioMgr : JAudioManager;
    ...
  public
    procedure onAudioFocusChange(focusChange: Integer); cdecl;
  end;
 
procedure TForm1.FormCreate(Sender: TObject);
var
  obj: JObject;
begin
  obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
  myAudioMgr := TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
  myAudioMgr.requestAudioFocus(Self, TJAudioManager.JavaClass.STREAM_MUSIC, 
TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
  myAudioMgr.abandonAudioFocus(Self);
  myAudioMgr := nil;
end;
 
procedure TForm1.onAudioFocusChange(focusChange: Integer);
begin
  Log.Add(focusChange); 
end;


See if either approach makes any difference.

--
Remy Lebeau (TeamB)

Hello!

I tried, but have this exception:

'Fatal error invoking interface' this line:

myAudioMgr.requestAudioFocus(Self, TJAudioManager.JavaClass.STREAM_MUSIC,
                               TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2015 5:22 PM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos wrote:

I tried, but have this exception:

'Fatal error invoking interface' this line:

myAudioMgr.requestAudioFocus(Self, TJAudioManager.JavaClass.STREAM_MUSIC, </div>
TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
<div class="jive-quote">

Then clearly it is not going to work having the TForm class implement the
interface directly. But you did not comment on the other stuff I mentioned.
Did you try my suggestion to have the TForm class maintain an active reference
to the TMyAudioFocusChangeListener object for the lifetime of the listener?
You seem to have just glossed over that example and ignored it.

--
Remy Lebeau (TeamB)
Carlos Phelippe

Posts: 39
Registered: 9/14/15
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 21, 2015 2:45 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Carlos wrote:

I tried, but have this exception:

'Fatal error invoking interface' this line:

myAudioMgr.requestAudioFocus(Self, TJAudioManager.JavaClass.STREAM_MUSIC, </div>
TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
<div class="jive-quote">

Then clearly it is not going to work having the TForm class implement the
interface directly. But you did not comment on the other stuff I mentioned.
Did you try my suggestion to have the TForm class maintain an active reference
to the TMyAudioFocusChangeListener object for the lifetime of the listener?
You seem to have just glossed over that example and ignored it.

--
Remy Lebeau (TeamB)

Hello!

Yes. I add this:

procedure TForm1.FormDestroy(Sender: TObject);
begin
  myAudioMgr.abandonAudioFocus(myListener);
  myListener := nil;
  myAudioMgr := nil;
end;


I tried also so:

TForm1 = class(TForm, JAudioManager_OnAudioFocusChangeListener)


But, same issue. :( :(

Edited by: Carlos Phelippe on Oct 21, 2015 2:51 AM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Jata to Delphi [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 21, 2015 5:09 PM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos wrote:

Yes. I add this:

That is only a small piece of the code I gave you. The important piece was
to add the myListener variable as a data member of the Form class. Did you
do that?

--
Remy Lebeau (TeamB)
Carlos Phelippe

Posts: 39
Registered: 9/14/15
Re: Jata to Delphi [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 22, 2015 5:00 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Carlos wrote:

Yes. I add this:

That is only a small piece of the code I gave you. The important piece was
to add the myListener variable as a data member of the Form class. Did you
do that?

--
Remy Lebeau (TeamB)

Hello!

I did so:

type
  TForm1 = class(TForm, JAudioManager_OnAudioFocusChangeListener)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    myAudioMgr : JAudioManager;
  public
    procedure onAudioFocusChange(focusChange: Integer); cdecl;
  end;
 
procedure TForm1.FormCreate(Sender: TObject);
var
  obj: JObject;
begin
  obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
  myAudioMgr := TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
  myAudioMgr.requestAudioFocus(Self, TJAudioManager.JavaClass.STREAM_MUSIC, 
TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
  myAudioMgr.abandonAudioFocus(Self);
  myAudioMgr := nil;
end;
 
procedure TForm1.onAudioFocusChange(focusChange: Integer);
begin
  Log.Add(focusChange); 
end;


But I also have this error:

'Fatal error invoking interface' this line:

myAudioMgr.requestAudioFocus(Self, TJAudioManager.JavaClass.STREAM_MUSIC,
TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Jata to Delphi [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 22, 2015 10:50 AM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos wrote:

I did so:

I am sorry, but I feel like I'm going around in circles with you.

Forget having TForm1 implement the JAudioManager_OnAudioFocusChangeListener
interface directly. It will clearly not work.

Did you, or did you not, try the other code I gave you, in its entirety?
Yes or no?

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    ...
  private
    myAudioMgr : JAudioManager;
    myListener : TMyAudioFocusChangeListener;
    procedure onMyAudioFocusChange(focusChange: Integer);
    ...
  end;
 
procedure TForm1.FormCreate(Sender: TObject);
var
  obj: JObject;
begin
  obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
  myAudioMgr := TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
  myListener := TMyAudioFocusChangeListener.Create;
  myListener.OnAudioFocusChanged := onMyAudioFocusChange;
 
  myAudioMgr.requestAudioFocus(myListener, TJAudioManager.JavaClass.STREAM_MUSIC, 
 TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
  myAudioMgr.abandonAudioFocus(myListener);
  myListener := nil;
  myAudioMgr := nil;
end;


--
Remy Lebeau (TeamB)
Carlos Phelippe

Posts: 39
Registered: 9/14/15
Re: Jata to Delphi [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 22, 2015 12:16 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Carlos wrote:

I did so:

I am sorry, but I feel like I'm going around in circles with you.

Forget having TForm1 implement the JAudioManager_OnAudioFocusChangeListener
interface directly. It will clearly not work.

Did you, or did you not, try the other code I gave you, in its entirety?
Yes or no?

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    ...
  private
    myAudioMgr : JAudioManager;
    myListener : TMyAudioFocusChangeListener;
    procedure onMyAudioFocusChange(focusChange: Integer);
    ...
  end;
 
procedure TForm1.FormCreate(Sender: TObject);
var
  obj: JObject;
begin
  obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
  myAudioMgr := TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
  myListener := TMyAudioFocusChangeListener.Create;
  myListener.OnAudioFocusChanged := onMyAudioFocusChange;
 
  myAudioMgr.requestAudioFocus(myListener, TJAudioManager.JavaClass.STREAM_MUSIC, 
 TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
  myAudioMgr.abandonAudioFocus(myListener);
  myListener := nil;
  myAudioMgr := nil;
end;


--
Remy Lebeau (TeamB)

I tested and no works too.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Jata to Delphi [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 22, 2015 12:47 PM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos wrote:

I tested and no works too.

If the code compiles and runs without crashing, but the listener is not being
called, then this is likely an Android issue, not a Delphi issue. Try asking
in some Android forums if there are any known issues with the audio listener
in general.

--
Remy Lebeau (TeamB)
Carlos Phelippe

Posts: 39
Registered: 9/14/15
Re: Jata to Delphi [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 23, 2015 7:46 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Carlos wrote:

I tested and no works too.

If the code compiles and runs without crashing, but the listener is not being
called, then this is likely an Android issue, not a Delphi issue. Try asking
in some Android forums if there are any known issues with the audio listener
in general.

--
Remy Lebeau (TeamB)

I see this:

AudioManager am = mContext.getSystemService(Context.AUDIO_SERVICE);
...
 
// Request audio focus for playback
int result = am.requestAudioFocus(afChangeListener,
                                 // Use the music stream.
                                 AudioManager.STREAM_MUSIC,
                                 // Request permanent focus.
                                 AudioManager.AUDIOFOCUS_GAIN);
   
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
    am.registerMediaButtonEventReceiver(RemoteControlReceiver);
    // Start playback.
}


my Delphi code:


   myNativeComponent := TJComponentName.JavaClass.init(SharedActivityContext.getPackageName(),
                                                     StringToJString(Application.Name));
 
   retorno := myAudioMgr.requestAudioFocus(myAudioListener,
                               TJAudioManager.JavaClass.STREAM_MUSIC,
                               TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
 
 
    if retorno = 1 then
      myAudioMgr.registerMediaButtonEventReceiver(myNativeComponent );
 
// in unit Androidapi.JNI.Media;
//    procedure registerMediaButtonEventReceiver(eventReceiver: JComponentName); cdecl; overload;
//    procedure registerMediaButtonEventReceiver(eventReceiver: JPendingIntent); cdecl; overload;
 
 
 


Edited by: Carlos Phelippe on Oct 23, 2015 9:00 AM

Edited by: Carlos Phelippe on Oct 23, 2015 9:18 AM
Carlos Phelippe

Posts: 39
Registered: 9/14/15
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 20, 2015 4:21 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Carlos wrote:

I run my app. I request audio focus. For sample, if I have 'vlc
android player' running and start my app 'vlc android player' stop.
So AUDIOFOCUS_REQUEST_GRANTED works correctly.

That is not what I asked you. But based on this info, I will have to assume
that "yes, requestAudioFocus() returns 1".

Now, my app is running and I start a music file (mp3) using
'vlc android player' my app needs to know when 'vlc android player'
request audio focus....

Assuming it does, which well-behaved apps should be doing...

but .onMyAudioFocusChange(focusChange: Integer); never is call.

Then you probably need to file a QP ticket with Embarcadero and ask them
about it.

FireMonkey implements Android listeners internally, such as in the Androidapi.JNI.ApkExpansion
and FMX.Advertising.Android units. They use the same technique described
in my earlier example, however the Advertising listener has one one additional
step - after the listener object is created, instead of passing it directly
to Android, Embarcadero wraps it in an adapter class:

FAdViewListener := TAdViewListener.Create(Self);
FJAd.setAdListener(TJAdListenerAdapter.JavaClass.init(FAdViewListener));


That adapter is implemented inside of a private Embarcadero library that
we don't have the source for, so I don't know what that adapter is actually
doing. On the other hand, the ApkExpansion listener has no adapter, it is
passed as-is to Android, just like in my example. So, I have to assume that
Delphi-written listeners CAN be passed to Android.

I suspect the more important issue is ARC reference counting on mobile platforms.
In my earlier example, and in your original code, the listener object has
no active reference for the entire lifetime of the TForm. So I would suggest
adding that (you need it anyway so you can abandon audio focus when you are
not playing audio):

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    ...
  private
    myAudioMgr : JAudioManager;
    myListener : TMyAudioFocusChangeListener;
    procedure onMyAudioFocusChange(focusChange: Integer);
    ...
  end;
 
procedure TForm1.FormCreate(Sender: TObject);
var
  obj: JObject;
begin
  obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
  myAudioMgr := TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
  myListener := TMyAudioFocusChangeListener.Create;
  myListener.OnAudioFocusChanged := onMyAudioFocusChange;
 
  myAudioMgr.requestAudioFocus(myListener, TJAudioManager.JavaClass.STREAM_MUSIC, 
TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
  myAudioMgr.abandonAudioFocus(myListener);
  myListener := nil;
  myAudioMgr := nil;
end;


Alternatively, it might be possible (I am not entirely sure) to have the
TForm class itself implement the listener interface, instead of using a separate
class:

type
  TForm1 = class(TForm, JAudioManager_OnAudioFocusChangeListener)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    ...
  private
    myAudioMgr : JAudioManager;
    ...
  public
    procedure onAudioFocusChange(focusChange: Integer); cdecl;
  end;
 
procedure TForm1.FormCreate(Sender: TObject);
var
  obj: JObject;
begin
  obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
  myAudioMgr := TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
  myAudioMgr.requestAudioFocus(Self, TJAudioManager.JavaClass.STREAM_MUSIC, 
TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
  myAudioMgr.abandonAudioFocus(Self);
  myAudioMgr := nil;
end;
 
procedure TForm1.onAudioFocusChange(focusChange: Integer);
begin
  Log.Add(focusChange); 
end;


See if either approach makes any difference.

--
Remy Lebeau (TeamB)

UP :( :(

Hello!

I tried, but have this exception:

'Fatal error invoking interface' this line:

myAudioMgr.requestAudioFocus(Self, TJAudioManager.JavaClass.STREAM_MUSIC,
TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
Carlos Phelippe

Posts: 39
Registered: 9/14/15
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 31, 2015 1:19 PM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos Phelippe wrote:
Remy Lebeau (TeamB) wrote:
Carlos wrote:

I run my app. I request audio focus. For sample, if I have 'vlc
android player' running and start my app 'vlc android player' stop.
So AUDIOFOCUS_REQUEST_GRANTED works correctly.

That is not what I asked you. But based on this info, I will have to assume
that "yes, requestAudioFocus() returns 1".

Now, my app is running and I start a music file (mp3) using
'vlc android player' my app needs to know when 'vlc android player'
request audio focus....

Assuming it does, which well-behaved apps should be doing...

but .onMyAudioFocusChange(focusChange: Integer); never is call.

Then you probably need to file a QP ticket with Embarcadero and ask them
about it.

FireMonkey implements Android listeners internally, such as in the Androidapi.JNI.ApkExpansion
and FMX.Advertising.Android units. They use the same technique described
in my earlier example, however the Advertising listener has one one additional
step - after the listener object is created, instead of passing it directly
to Android, Embarcadero wraps it in an adapter class:

FAdViewListener := TAdViewListener.Create(Self);
FJAd.setAdListener(TJAdListenerAdapter.JavaClass.init(FAdViewListener));


That adapter is implemented inside of a private Embarcadero library that
we don't have the source for, so I don't know what that adapter is actually
doing. On the other hand, the ApkExpansion listener has no adapter, it is
passed as-is to Android, just like in my example. So, I have to assume that
Delphi-written listeners CAN be passed to Android.

I suspect the more important issue is ARC reference counting on mobile platforms.
In my earlier example, and in your original code, the listener object has
no active reference for the entire lifetime of the TForm. So I would suggest
adding that (you need it anyway so you can abandon audio focus when you are
not playing audio):

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    ...
  private
    myAudioMgr : JAudioManager;
    myListener : TMyAudioFocusChangeListener;
    procedure onMyAudioFocusChange(focusChange: Integer);
    ...
  end;
 
procedure TForm1.FormCreate(Sender: TObject);
var
  obj: JObject;
begin
  obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
  myAudioMgr := TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
  myListener := TMyAudioFocusChangeListener.Create;
  myListener.OnAudioFocusChanged := onMyAudioFocusChange;
 
  myAudioMgr.requestAudioFocus(myListener, TJAudioManager.JavaClass.STREAM_MUSIC, 
TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
  myAudioMgr.abandonAudioFocus(myListener);
  myListener := nil;
  myAudioMgr := nil;
end;


Alternatively, it might be possible (I am not entirely sure) to have the
TForm class itself implement the listener interface, instead of using a separate
class:

type
  TForm1 = class(TForm, JAudioManager_OnAudioFocusChangeListener)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    ...
  private
    myAudioMgr : JAudioManager;
    ...
  public
    procedure onAudioFocusChange(focusChange: Integer); cdecl;
  end;
 
procedure TForm1.FormCreate(Sender: TObject);
var
  obj: JObject;
begin
  obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
  myAudioMgr := TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
  myAudioMgr.requestAudioFocus(Self, TJAudioManager.JavaClass.STREAM_MUSIC, 
TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
  myAudioMgr.abandonAudioFocus(Self);
  myAudioMgr := nil;
end;
 
procedure TForm1.onAudioFocusChange(focusChange: Integer);
begin
  Log.Add(focusChange); 
end;


See if either approach makes any difference.

--
Remy Lebeau (TeamB)

UP :( :(

Hello!

I tried, but have this exception:

'Fatal error invoking interface' this line:

myAudioMgr.requestAudioFocus(Self, TJAudioManager.JavaClass.STREAM_MUSIC,
TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);

Hello!

Java code:

AudioManager am = mContext.getSystemService(Context.AUDIO_SERVICE);
...
 
// Request audio focus for playback
int result = am.requestAudioFocus(afChangeListener,
                                 // Use the music stream.
                                 AudioManager.STREAM_MUSIC,
                                 // Request permanent focus.
                                 AudioManager.AUDIOFOCUS_GAIN);
   
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
    am.registerMediaButtonEventReceiver(RemoteControlReceiver);
    // Start playback.
}

Delphi code:

   myJComponent := TJComponentName.JavaClass.init(SharedActivityContext.getPackageName(),
                                                     StringToJString(Application.Name));
 
   retorno := myAudioMgr.requestAudioFocus(myAudioListener,
                               TJAudioManager.JavaClass.STREAM_MUSIC,
                               TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
 
 
    if retorno = 1 then
      myAudioMgr.registerMediaButtonEventReceiver(myJComponent );
 
// in unit Androidapi.JNI.Media;
//    procedure registerMediaButtonEventReceiver(eventReceiver: JComponentName); cdecl; overload;
//    procedure registerMediaButtonEventReceiver(eventReceiver: JPendingIntent); cdecl; overload;
 


Correct my Delphi code above?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 2, 2015 10:24 AM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos wrote:

Correct my Delphi code above?

We have already been over this. I gave you the relevent Delphi code earlier.
If Android is not calling your audio listener, then either Android itself
has a problem, or there is a problem in Delphi's underlying bridge framework.
I can't tell you which is actually the case. I am not an Android developer.
But the problem is not the code provided, it has to be elsewhere.

--
Remy Lebeau (TeamB)
Carlos Phelippe

Posts: 39
Registered: 9/14/15
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 2, 2015 12:15 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Carlos wrote:

Correct my Delphi code above?

We have already been over this. I gave you the relevent Delphi code earlier.
If Android is not calling your audio listener, then either Android itself
has a problem, or there is a problem in Delphi's underlying bridge framework.
I can't tell you which is actually the case. I am not an Android developer.
But the problem is not the code provided, it has to be elsewhere.

--
Remy Lebeau (TeamB)

Hello Remy Lebeau!

Java has this code:

if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
    am.registerMediaButtonEventReceiver(RemoteControlReceiver);
    // Start playback.
}


Delphi this no necessary?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Jata to Delphi
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 2, 2015 12:45 PM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos wrote:

Java has this code:

if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
am.registerMediaButtonEventReceiver(RemoteControlReceiver);
// Start playback.
}


Delphi this no necessary?

Not for the purpose of receiving audio focus change events, no.

Read the Android documentation:

http://developer.android.com/training/managing-audio/volume-playback.html

registerMediaButtonEventReceiver() registers your app to receive media button
Intents, which allow the user (or other apps) to control your app's audio
playback behavior - play, stop, pause, etc.

That has nothing to do with your audio focus listener. They are two separate
things.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02