I am working on an application that has media playing features.
I would like to honor AudioFocus. I first request AudiFocus:
audioManager.requestAudioFocus(new CustomOnAudioFocusChangeListener(), AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
This call returns either AUDIOFOCUS_REQUEST_FAILED or AUDIOFOCUS_REQUEST_GRANTED.
I guess I shouldn't start playback if I receive AUDIOFOCUS_REQUEST_FAILED. But then what to do?
Will my CustomOnAudioFocusChangeListener be notified when focus becomes available or is it only when you got AUTOFOCUS_REQUEST_GRANTED that it starts getting updates?
Should I inform the user and ask him to try again later? Or retry programmatically after some time?
Thanks in advance
What to do depends on how you want your app to react. You shouldn't start playing, you may want to message your user. Or if its something non-critical, you may silently ignore the failure and move on.
I believe you only get updates on the listener on success. You get the updates then so if you're lowered you can choose to duck your output or pause until you regain.
Related
I have two Android devices running separate TokBox apps which are trying to communicate with each other through video chat. I am having a problem in getting the OnStreamReceived event from one of my application which is publishing the video chat. But the application that subscribes the video triggers the event. I need the event to be triggered on the publishing side. Can anybody let me know the reason? Thanks.
Tokbox QA staff here.
Not sure what you mean with "separate Tokbox apps", but, if you use the same API Key for both ends, and you connect to the same session, the OnStreamReceived event would be received by the subscribers, not the publisher. This event will be triggered when another client publishes a stream, which means that the subscriber will not trigger the event. You can find further information here:
https://tokbox.com/developer/guides/subscribe-stream/android/#detect_streams
TokBox Developer Evangelist here.
As Fran mentioned, the onStreamReceived will only fire when another client in the session publishes. If you want to know when the publisher has started to publish from the publisher's perspective, please use this method:
public void onStreamCreated(PublisherKit publisherKit, Stream stream) {
// publishing - do something
}
About half the time the Publisher.StreamCreated event doesn't fire. The breakpoint simply isn't hit and the subscribers are therefore not notified since the publisher isn't sending anything. It's really hit or miss and frustrating.
I am writing a Multiplayer game using Google's TurnBasedMultiplayer API and calling takeTurn(). I have three players in the game, and besides the player who is calling takeTurn, I am finding that one player receives the update and onTurnBasedMatchReceived() is correctly called, yet the other player doesn't receive the update, onTurnBasedMatchReceived() is not called.
Can someone supply me with a possible reason not all players are receiving the updates? I note that the player who doesn't receive the update needs to go back to the Match Inbox and choose the relevant match again, and then it can be seen that the game is in fact updated.
Is the player who is not receiving the updates completely in the match? A player who hasn't accepted an invitation won't receive calls to onTurnBasedMatchUpdated.
Additionally, when a player receives an invitation, this comes to an invitation listener, not a match updated listener. If you're trying to use the match updated listener for both, that would also explain why you're not getting an update.
Have you activated the listener. I use code like this on my main activity...
public class GameScreen extends Activity implements OnInvitationReceivedListener,
OnTurnBasedMatchUpdateReceivedListener {
...
}
I'm currently using the READ_PHONE_STATE permission in Android to pause my media player when there's a call, and to resume playback when the call is over. The permission seems to scare a lot of people, so I was wondering if there was an alternative to catching the starting and stopping of a phone call without it. Any help is appreciated. Thanks!
If you want to adjust your audio output in response to something else wanting to perform audio output (e.g., an incoming phone call), look into Android's audio focus support.
READ_PHONE_STATE, as noted, is a bit of a scary permission. Moreover, it only deals with phone calls, and not other things that might need the same capability (e.g., VOIP calls, as AFAIK those don't tie into READ_PHONE_STATE-enabled stuff).
Unfortunately, audio focus is not a substitute for READ_PHONE_STATE. My app has to use both. The standard phone app on my Galaxy S3 I9300/ Android 4.3 doesn't seem to request the audio focus at all. The TelephonyManager class gives you a way to detect the end of the phone call (by sending the CALL_STATE_IDLE state update). The AudioManager doesn't seem to do anything similar, so even if audio focus could be used, it would not be as useful. And, from what I see in the documentation, there doesn't seem to be a narrower permission than READ_PHONE_STATE that would allow the app to read the phone state but not the call information. If I'm wrong about any of this, please correct me.
Unfortunately, audio focus is not a substitute for READ_PHONE_STATE. My app has to use both. The standard phone app on my Galaxy S3 I9300/ Android 4.3 doesn't seem to request the audio focus at all. The TelephonyManager class gives you a way to detect the end of the phone call (by sending the CALL_STATE_IDLE state update). The AudioManager doesn't seem to do anything similar, so even if audio focus could be used, it would not be as useful. And, from what I see in the documentation, there doesn't seem to be a narrower permission than READ_PHONE_STATE that would allow the app to read the phone state but not the call information. If I'm wrong about any of this, please correct me.
I have an audio app which will drive an external audio amplifier. In the code I set the maximum audio level:
int maxAudioVolume = audioManager.getStreamMaxVolume(AudioManager.STREA M_MUSIC);
audioManager.setStreamVolume(AudioManager.STREAM_M USIC,maxAudioVolume,0);
If I plug in the amplifier, then always the following alert is issued:
Raise volume above recommended level?
This is becoming irritating. Does anybody know how the alert can be avoided? Actually, this issue has been addressed in other forums, and sometimes it was solved, but always by using some app. Thus it should be possible, but the question is: how?
Wouter Boeke
See this:
Disable sound safe level notification in android & xda-developers; Unsafe Volume - disable safe media volume popup/check
Basically you need to root your phone, and set config_safe_media_volume_enabled at boot time to false. Which happens I think if the user clicks ok, you can't get rid of it without root.
Could it be possible now, which we can develop an Android application having the following requirement for its working steps
Automatic receive the call, then
Play some sound out to the caller, wait for DTMF response, then
Record the caller sound (in the case that they permit, by pressing 1 as DTMF response)
Callee can play back the recoreded sound later.
Thank for all answers in advance .....
Hey I am also making same application...for Automatic receive call you need to change Source Code of android. I have done it successfully with froyo 2.2. There is method answerCall(Phone phone) in PhoneUtils.java file with that you can automatic receive call.
I am also searching for DTMF....but till now i didn't get anything which can be helpful....for DTMF decoding....
the first point seems possible. check the state of call if it is ringing state the program can auto attend it for you..you can find more information in this link.
http://www.devlper.com/2010/08/detecting-incoming-and-outgoing-calls-in-android/
http://prasanta-paul.blogspot.com/2010/09/call-control-in-android.html