Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: Audio Focus


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 5 - Last Post: Aug 28, 2015 11:29 PM Last Post By: Remy Lebeau (Te...
Carlos Phelippe

Posts: 39
Registered: 9/14/15
Audio Focus  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 24, 2015 10:58 AM
Hello!

I need to know when my app has audio focus.

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

How?
Carlos Phelippe

Posts: 39
Registered: 9/14/15
Re: Audio Focus  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 25, 2015 3:28 AM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos Phelippe wrote:
Hello!

I need to know when my app has audio focus.

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

How?

I am trying so:

  TOnAudioFocusChange = procedure(focusChange: System.Integer) of object;
  TmyJAudioManagerListener = class(TJavaLocal, JAudioManager_OnAudioFocusChangeListener)
  private
    FOnAudioFocusChange : TOnAudioFocusChange;
  public
    property myOnAudioFocusChange : TOnAudioFocusChange read FOnAudioFocusChange write FOnAudioFocusChange;
    Constructor Create;
    Destructor Destroy; Override;
    procedure onAudioFocusChange(focusChange: System.Integer); cdecl;
  end;
 
{ TmyJAudioManagerListener }
 
constructor TmyJAudioManagerListener.Create;
begin
 
end;
 
destructor TmyJAudioManagerListener.Destroy;
begin
  inherited;
end;
 
procedure TmyJAudioManagerListener.onAudioFocusChange(focusChange: System.Integer);
begin
  if Assigned(FOnAudioFocusChange) then
    FOnAudioFocusChange(focusChange);
 
end;


And using:

procedure TForm1.FormCreate(Sender: TObject);
var
  i, j, retorno : integer;
  obj : JObject;
  ResolveInfo: JResolveInfo;
  Manager: JPackageManager;
begin
 
   NativeComponent := TJComponentName.JavaClass.init(SharedActivityContext.getPackageName(),
                                                     StringToJString(Application.Name));
   myAudioListener := TmyJAudioManagerListener.Create;
 
   obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
   myAudioMgr :=  TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
 
   retorno := myAudioMgr.requestAudioFocus(myAudioListener,
                               TJAudioManager.JavaClass.STREAM_MUSIC,
                               TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
 
    if retorno = 1 then
      myAudioMgr.registerMediaButtonEventReceiver(NativeComponent);
 
   if Assigned(myAudioListener)  then
   begin
     myAudioListener.myOnAudioFocusChange := self.onMyAudioFocusChange;
   end;
 
end;
 
 
procedure TForm1.onMyAudioFocusChange(focusChange: System.Integer);
begin
  //This never is called 
  ListBox1.Items.Add(inttostr(focusChange));
end;
 
 


This never is called:

procedure TForm1.onMyAudioFocusChange(focusChange: System.Integer);
begin
ListBox1.Items.Add(inttostr(focusChange));
end;
Carlos Phelippe

Posts: 39
Registered: 9/14/15
Re: Audio Focus  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 25, 2015 11:22 AM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos Phelippe wrote:
Carlos Phelippe wrote:
Hello!

I need to know when my app has audio focus.

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

How?

I am trying so:

  TOnAudioFocusChange = procedure(focusChange: System.Integer) of object;
  TmyJAudioManagerListener = class(TJavaLocal, JAudioManager_OnAudioFocusChangeListener)
  private
    FOnAudioFocusChange : TOnAudioFocusChange;
  public
    property myOnAudioFocusChange : TOnAudioFocusChange read FOnAudioFocusChange write FOnAudioFocusChange;
    Constructor Create;
    Destructor Destroy; Override;
    procedure onAudioFocusChange(focusChange: System.Integer); cdecl;
  end;
 
{ TmyJAudioManagerListener }
 
constructor TmyJAudioManagerListener.Create;
begin
 
end;
 
destructor TmyJAudioManagerListener.Destroy;
begin
  inherited;
end;
 
procedure TmyJAudioManagerListener.onAudioFocusChange(focusChange: System.Integer);
begin
  if Assigned(FOnAudioFocusChange) then
    FOnAudioFocusChange(focusChange);
 
end;


And using:

procedure TForm1.FormCreate(Sender: TObject);
var
  i, j, retorno : integer;
  obj : JObject;
  ResolveInfo: JResolveInfo;
  Manager: JPackageManager;
begin
 
   NativeComponent := TJComponentName.JavaClass.init(SharedActivityContext.getPackageName(),
                                                     StringToJString(Application.Name));
   myAudioListener := TmyJAudioManagerListener.Create;
 
   obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
   myAudioMgr :=  TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
 
   retorno := myAudioMgr.requestAudioFocus(myAudioListener,
                               TJAudioManager.JavaClass.STREAM_MUSIC,
                               TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
 
    if retorno = 1 then
      myAudioMgr.registerMediaButtonEventReceiver(NativeComponent);
 
   if Assigned(myAudioListener)  then
   begin
     myAudioListener.myOnAudioFocusChange := self.onMyAudioFocusChange;
   end;
 
end;
 
 
procedure TForm1.onMyAudioFocusChange(focusChange: System.Integer);
begin
  //This never is called 
  ListBox1.Items.Add(inttostr(focusChange));
end;
 
 


This never is called:

procedure TForm1.onMyAudioFocusChange(focusChange: System.Integer);
begin
ListBox1.Items.Add(inttostr(focusChange));
end;

Sorry, but somebody?
Carlos Phelippe

Posts: 39
Registered: 9/14/15
Re: Audio Focus  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 27, 2015 3:21 AM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos Phelippe wrote:
Carlos Phelippe wrote:
Carlos Phelippe wrote:
Hello!

I need to know when my app has audio focus.

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

How?

I am trying so:

  TOnAudioFocusChange = procedure(focusChange: System.Integer) of object;
  TmyJAudioManagerListener = class(TJavaLocal, JAudioManager_OnAudioFocusChangeListener)
  private
    FOnAudioFocusChange : TOnAudioFocusChange;
  public
    property myOnAudioFocusChange : TOnAudioFocusChange read FOnAudioFocusChange write FOnAudioFocusChange;
    Constructor Create;
    Destructor Destroy; Override;
    procedure onAudioFocusChange(focusChange: System.Integer); cdecl;
  end;
 
{ TmyJAudioManagerListener }
 
constructor TmyJAudioManagerListener.Create;
begin
 
end;
 
destructor TmyJAudioManagerListener.Destroy;
begin
  inherited;
end;
 
procedure TmyJAudioManagerListener.onAudioFocusChange(focusChange: System.Integer);
begin
  if Assigned(FOnAudioFocusChange) then
    FOnAudioFocusChange(focusChange);
 
end;


And using:

procedure TForm1.FormCreate(Sender: TObject);
var
  i, j, retorno : integer;
  obj : JObject;
  ResolveInfo: JResolveInfo;
  Manager: JPackageManager;
begin
 
   NativeComponent := TJComponentName.JavaClass.init(SharedActivityContext.getPackageName(),
                                                     StringToJString(Application.Name));
   myAudioListener := TmyJAudioManagerListener.Create;
 
   obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
   myAudioMgr :=  TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
 
   retorno := myAudioMgr.requestAudioFocus(myAudioListener,
                               TJAudioManager.JavaClass.STREAM_MUSIC,
                               TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
 
    if retorno = 1 then
      myAudioMgr.registerMediaButtonEventReceiver(NativeComponent);
 
   if Assigned(myAudioListener)  then
   begin
     myAudioListener.myOnAudioFocusChange := self.onMyAudioFocusChange;
   end;
 
end;
 
 
procedure TForm1.onMyAudioFocusChange(focusChange: System.Integer);
begin
  //This never is called 
  ListBox1.Items.Add(inttostr(focusChange));
end;
 
 


This never is called:

procedure TForm1.onMyAudioFocusChange(focusChange: System.Integer);
begin
ListBox1.Items.Add(inttostr(focusChange));
end;

Sorry, but somebody?

Up :( :(
Carlos Phelippe

Posts: 39
Registered: 9/14/15
Re: Audio Focus  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 28, 2015 8:59 AM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos Phelippe wrote:
Carlos Phelippe wrote:
Carlos Phelippe wrote:
Carlos Phelippe wrote:
Hello!

I need to know when my app has audio focus.

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

How?

I am trying so:

  TOnAudioFocusChange = procedure(focusChange: System.Integer) of object;
  TmyJAudioManagerListener = class(TJavaLocal, JAudioManager_OnAudioFocusChangeListener)
  private
    FOnAudioFocusChange : TOnAudioFocusChange;
  public
    property myOnAudioFocusChange : TOnAudioFocusChange read FOnAudioFocusChange write FOnAudioFocusChange;
    Constructor Create;
    Destructor Destroy; Override;
    procedure onAudioFocusChange(focusChange: System.Integer); cdecl;
  end;
 
{ TmyJAudioManagerListener }
 
constructor TmyJAudioManagerListener.Create;
begin
 
end;
 
destructor TmyJAudioManagerListener.Destroy;
begin
  inherited;
end;
 
procedure TmyJAudioManagerListener.onAudioFocusChange(focusChange: System.Integer);
begin
  if Assigned(FOnAudioFocusChange) then
    FOnAudioFocusChange(focusChange);
 
end;


And using:

procedure TForm1.FormCreate(Sender: TObject);
var
  i, j, retorno : integer;
  obj : JObject;
  ResolveInfo: JResolveInfo;
  Manager: JPackageManager;
begin
 
   NativeComponent := TJComponentName.JavaClass.init(SharedActivityContext.getPackageName(),
                                                     StringToJString(Application.Name));
   myAudioListener := TmyJAudioManagerListener.Create;
 
   obj := SharedActivityContext.getSystemService(TJContext.JavaClass.AUDIO_SERVICE);
   myAudioMgr :=  TJAudioManager.Wrap((obj as ILocalObject).GetObjectID);
 
 
   retorno := myAudioMgr.requestAudioFocus(myAudioListener,
                               TJAudioManager.JavaClass.STREAM_MUSIC,
                               TJAudioManager.JavaClass.AUDIOFOCUS_GAIN);
 
    if retorno = 1 then
      myAudioMgr.registerMediaButtonEventReceiver(NativeComponent);
 
   if Assigned(myAudioListener)  then
   begin
     myAudioListener.myOnAudioFocusChange := self.onMyAudioFocusChange;
   end;
 
end;
 
 
procedure TForm1.onMyAudioFocusChange(focusChange: System.Integer);
begin
  //This never is called 
  ListBox1.Items.Add(inttostr(focusChange));
end;
 
 


This never is called:

procedure TForm1.onMyAudioFocusChange(focusChange: System.Integer);
begin
ListBox1.Items.Add(inttostr(focusChange));
end;

Sorry, but somebody?

Up :( :(

Sorry, but up again :( :(
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Audio Focus  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 28, 2015 11:29 PM   in response to: Carlos Phelippe in response to: Carlos Phelippe
Carlos wrote:

Sorry, but up again :( :(

I think it is safe to say that at this point, noone here has an answer for
you.

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

Server Response from: ETNAJIVE02