I've written a videoplayer for Android based on Flash (10.2) which plays videostreams. In some cases (*), the player begins to buffer for quite some time.
Now, while the player is acually playing the stream, Flash (somehow) signals the OS to prevent entering the sleep-mode. But while buffering, this is not the case and the phone will eventually enter sleep mode before the stream has restarted. So the user has to unlock the phone again - not very convenient.
Is there a way to set a signal with Flash/AS3 to prevent the Andoid-phone to go into sleep mode?
(*) mostly over the mobile network when the network access performes a handover between 3G and 2G or vice versa
just use
// no dimming
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
in your mxml or as file.
Related
I've developed an application that streams music (via internet connection) using service and having trubles streaming content without phone going idle.
While i was developing my application each time i tried case mentioned below the music was reproducing fine.
Use case : search song, select song from results, play song, screen off -> auto play next song from result list
I'm developing using real device - Huawei Mate 20 Lite - OS v8.01 so while debugging it gotta use USB cabel.
Like i said following the use case above while hooked on USB the auto play while screen off works good. The case it doesn't work good is when the cable is not connected (only mobile data turned on).
What I've figured out is that phone when connected on USB is probably keeping the device awake and it doesn't go to idle mode while when not connected after around 5mins the device probably shuts down processes that cost energy or it shuts down connection to mobile data i'm not sure and there's where i need you guys.
Also I've tested app using HTC U Play - OS v6.0 and the streaming goes smooth without interrupts while screen off and phone wasn't touched for 10+mins.
Also I've tried to acquire wakelock inside oncreate and without releasing it just to see if it helps and it doesn't.
pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock");
wl.acquire();
This problem you are facing can be due to the fact that after Andriod 6.0, all apps are getting optimized for optimizing the battery usage.
If you really think, the reason behind the application to go killed is inactivity. Then, probably, its because of battery optimization software itself.
You can enable another permission while installing the app on the device where you can update the list of unoptimized app by adding an entry for your app.
Originally, you will be able to do the manual settings by following below instruction.
. Head for the ‘Settings‘ app and then ‘Battery‘
. On the ‘three dots‘ menu, top right, you’ll find ‘Battery optimisation‘.
. Here you’ll see a list of all applications which shouldn’t be ‘optimised‘ (for which read ‘can be handled by Doze and App Standby’) – by default the list is usually very small, with almost all apps enabled for ‘optimisation’. Which is fine for general users, but if, like me, you want a few applications to live outside of the new battery optimisations, then tap on the ‘Not optimised‘ pick list and choose ‘All apps‘
. As you’d expect, every application on your phone is listed (this may be quite long) – swipe down until you find the application(s) that you particularly want to always keep running. Tap on the application name
. From the two choices, check the box for ‘Don’t optimise‘.
I am using the logic from Android : Switching audio between Bluetooth and Phone Speaker is inconsistent to switch output between earpiece, speaker, and bluetooth. Here is the code:
//For BT
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.startBluetoothSco();
mAudioManager.setBluetoothScoOn(true);
//For phone ear piece
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mAudioManager.stopBluetoothSco();
mAudioManager.setBluetoothScoOn(false);
mAudioManager.setSpeakerphoneOn(false);
//For phone speaker(loadspeaker)
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mAudioManager.stopBluetoothSco();
mAudioManager.setBluetoothScoOn(false);
mAudioManager.setSpeakerphoneOn(true);
This logic works as expected as long as no other application has used audio (media player, phone, etc.). If I run my application after running the other application, the logic goes haywire. The audio still works except the destination output is not what is expected. For example, instead of speakerphone, the output may go to earpiece.
Note that I run my application after quitting from the other application. There is no overlap.
It appears audio manager settings are not specific to an application and may mess up other applications. I am wondering if there is a way to reset audio manager before setting my mode. Regards.
In my Android app, the user gets to specifically select the audio output between internal speakers and earphone. Here is my routine to turn the speaker phone on:
static void useSpeaker(Context ctx) {
AudioManager am = (AudioManager)ctx.getSystemService(Context.AUDIO_SERVICE);
am.setMode(AudioManager.MODE_NORMAL);
am.setSpeakerphoneOn(true);
}
Once the audio is set to speakers, even if you plug in the earphone, the output still goes through the speaker. I have verified on a number of different tablets and phones that this logic works.
However, on one device, once the earphone is plugged in, the audio output automatically switches from speakers to earphone.
I am wondering if there is something else that I need to take care of in the code. Or, is it just this device ignoring my directive? Regards.
Before we get to the details, a little context:
Car: Nissan Note (UK 2011 Model)
Device: Nexus 4
OS: Android 4.3 Stock
I'm trying to create an app to do speech recognition and synthesis in my car while the phone is connected over bluetooth. The car audio system does not provide it's own voice recognition, but instead delegates this to the phone by triggering an intent android.intent.action.VOICE_COMMAND
The default app on the device for handling this is the Google Search app, which has a specific activity for hands-free dialling. This app has terrible speech recognition but does demonstrate how the system is supposed to work - when activated the car displays "Voice recognition active" on the phone screen while the app is running, and then hides it when the app exits.
The problem I have is that while I can make this label appear by calling AudioManager.startBluetoothSco() and thus play audio through the car speakers and record it through the car microphone, but AudioManager.stopBluetoothSco() does not disable this mode in the car, and it remains displaying 'Voice recognition active'. This is a problem since the car will not then launch the app until the bluetooth connection has been closed and re-opened.
My experiments have verified that it is AudioManager.startBluetoothSco() which enables the mode in the car, and that AudioManager.stopBluetoothSco() appears to have the effect of changing the ambient sound produced by the car (a very faint hiss usually heard when the audio system is active will stop when this command is issued) but no other effect is seen.
I am unsure if something else is activated implicitly with the call to AudioManager.startBluetoothSco() which must then be implicitly stopped, but I'm currently out of ideas for what to try.
After a lot more research I came across this: http://developer.android.com/reference/android/bluetooth/BluetoothHeadset.html#stopVoiceRecognition%28android.bluetooth.BluetoothDevice%29
which would appear to be related to the problem. After calling startVoiceRecognition and stopVoiceRecognition as appropriate, things appeared to return to their normal state.
I am trying to identify how to route a very short audio stream (a notification) to a bluetooth headphone that is already paired with the device, while the device is ringing.
When I play any audio at any time, it is routed to the bluetooth device, no problem.
But if I try to start playing the audio when receiving an android.intent.action.PHONE_STATE, in RINGING state, the audio is not routed as expected.
I can see that the AudioManager's setBluetoothA2dpOn method has became deprecated, but I actually tried it but is seems has no effect.
I have tried the MediaRouter object, but I can see that MediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_AUDIO) points to the RouteInfo of the Bluetooth device while the device is ringing, and the AudioManager.isBluetoothA2dpOn is true.
So, can any one tell me why the audio route is like this in the ringing moment? is there any way to force the audio to be routed to the Bluetooth device in such case?
[UPDATED]
I have tried again today and I have discovered something that may be the cause of the problem.
I have created a BroadcaseReceiver to detect the change in the android.intent.action.PHONE_STATE. if an intent is received and the state is currently ringing, check for AudioManager's mode and you will find it is MODE_NORMAL. but few seconds later the phone will start actually ringing and the mode is going to be changed into MODE_RINGTONE. trying to manually set the mode using the method setMode(AudioManager.MODE_NORMAL) is useless then, the state remains MODE_RINGTONE even after setting it to MODE_NORMAL.
Now, I think the cause of the problem is that in the MODE_RINGTONE mode, all the streams are directed to the phone speaker and here there is no way offered by the android system to change the mode.
I think the Media player realease the bluetooth connection when the phone is ringing. You can try to obtain the bluetooth audio connection and see if Media player now play through your obtained connection. You can use my class at my answer Using the Android RecognizerIntent with a bluetooth headset and see if it works. The audio in the class is Sco only.
As stated in the JavaDoc for the StartBluetoothSco method:
Note that the phone application always has the priority on the usage of the SCO connection for telephony. If this method is called while the phone is in call it will be ignored. Similarly, if a call is received or sent while an application is using the SCO connection, the connection will be lost for the application and NOT returned automatically when the call ends.`
I tried to start sco then play a music clip in normal mode, it played to the Bluetooth headset without problems, although I couldnot stop the microphone that caused the input stream plays to the headset. I then tried to call my target phone from another phone while the music is still playing, I found that the stream has got redirected automatically to the phone speaker. After the ringing mode is finished, the stream did not get redirected again to the Bluetooth headset and I think that behavior is normal according to what is stated in the JavaDoc above.
My guessing is that Android tries to protect the ringing and in-call modes as possible in order not to allow any unwanted interference from applications. In other words, when in ringing mode then no sound is going to be played to the headset until the call is accepted, and you cannot even change the AudioManager mode from ringing to another mode, your call for mode setter will be ignored.
I have tried the AudioTrack instead of MediaPlayer, but that makes no difference.
I have then tried the TextToSpeech engine like this:
in the main activity, initialize on create:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textToSpeech=new TextToSpeech(this, this);
textToSpeech.setLanguage(Locale.US);
textToSpeech.addEarcon("[wwww]", "XXXXXXXXXXXXXXXXXXXXXXX", R.raw.a);
}
in the broadcast receiver class when rining starting the Bluetooth utility class and adding the below to the onScoAudioConnected method
textToSpeech.playEarcon("[wwww]", TextToSpeech.QUEUE_FLUSH, null);
This did not work too.