Flash code 'pauses' when in inactive tab? - browser

Does flash pause its execution somehow if the browser tab in which its residing is inactive?
I developed a multiplayer game using cirrus and when I tried to play it by switching tabs, making a move in each tab, there were some inconsistencies regarding the way the game executed as if the inactive tab pauses the flash execution and then resume once it was active.
The game works perfectly in standalone flash player/debugger.

Yes, in 10.1 they introduced throttle:
http://saumyaray.wordpress.com/2011/07/14/flashplayer-throttle-solving-a-problem-or-creating-one/

Search your (lib) code for listeners to Event.ACTIVATE and Event.DEACTIVATE.
Those are commonly used to pause a game when it doesn't have focus.

Related

How to capture Bluetooth Controller while Mac App is inactive?

I am attempting to write a small helper app for macOS that captures the input of a Nimbus Steel Series game controller and converts it to keyboard and mouse events for another application (a game that does not support controllers).
In my first attempt I used GCController but as soon as the app becomes inactive no more events are received from the controller. There seems to be no way to change this.
In my second attempt I used CBCentralManager to discover the controller, hoping I could work with it using standard Bluetooth services. But the controller does not even show up in a scan, either with the controller being connected or disconnected. I find devices around the house (iPads, iPhones, smart tv's, computers), but no peripheral that identifies itself as Nimbus. However, there are a couple nil peripherals which I suppose are auxiliary peripherals from Apple devices such as the Magic Mouse or the Wireless Keyboard.
In my third attempt I tried to make the main window an NSPanel in HUD style. The panel stays afloat but it still becomes inactive when I click elsewhere. No controller events received. I thought maybe I could show the panel above the fullscreen game in a corner somehow. But it still needs to be active to get GCController events, then the game would not get events.
Are there any other options to receive game controller inputs which the app is inactive?
Would it work via IOKit? I have been hesitant to use IOKit so far because I was hoping to resolve this issue without it, being a very lowlevel API.
I solved this problem using the IOHIDManager functions. The callbacks receive events even if the app is not active.

OpenAL play sound, dealloc one instance, all the other's sound dispeared?

I use OpenAL to play sound from network streaming in my NPAPI plugin (browser plugin). When I open more than one browser's tab, I close one of the tabs, the others' sound also dispeared. Anyone could give me some help? Or anyone can give me some advice for playing stream audio, such as audio from mic or such devices. When I use audio queue service, it still cannot surport multi instances. For work's reason, I cannot paste my code in there, sorry about that. I use OpenAL some way as Apple's Developer's example - oalTouch, the link is
https://developer.apple.com/library/ios/samplecode/oalTouch/Introduction/Intro.html
I use the system default device to play sound, which means I use alcOpenDevice(NULL) to open the device.
When a page with your plugin closes, the corresponding instance of your plugin is destroyed; there's one instance per plugin that is simultaneously active in the browser. Presumably the problem is that you are doing something in your plugin instance teardown that tears down something global.
Without being able to see anything about what your code is doing, it's hard to see how anyone can help figure out what that thing is.
Now I have found the reason. OpenAL do support multi audio source, but when I use it as the oalTouch example, I did not change anything. The reason why I close one browser's tab, the sound stopped is that the device is closed by me when I destroy the plugin instance. So if I want to use it in multi instances, I should design it carefully, and this is my design: I use static var to indicate if the default device is opened, if it is opened, I do not open it again (use alOpenDevice(NULL) method). But for different tabs, I use different sourceId (alGenSource(...) method is used). When I close the browser's teb, the plugin instance is destroyed too. I use the static variable to check if there still have plugin instance use the default audio device, if yes, do nothing, otherwise close the device.

SW2 Control Extension stop updating the Display when the smartphone is idle

I'm working on a Control Extension for Sony SmartWatch 2 that needs to update a TextView every second on the SW2 Display.
It happens that if I've my Smartphone connected via USB or when USB disconnected if I've my Smartphone screen active, the Control Extension works as expected on SmartWatch 2.
But soon my SmartPhone screen idles, the control extension stops the regular TextView updates. First starts breaking and eventually get stuck. The Extension is not closed by the Host Application and the SW2 continues well paired with the Smartphone. In fact if I touch the display, the Extension appears to recover state for some moments with a few TextView updates, but rapidly breaks and get stuck again.
Meanwhile, if I turn ON my Smartphone screen, the control extension recovers the state and resume the normal TextView updates.
It seems that when the smartphone idles it stops to send the regular bluetooth messages to the SW2. I've tried many solutions to avoid this behaviour, even set the keepRunningWhenConnected to true. But the behaviour is allways the same.
Is anyone also having this problem or have a clue for the solution?
Thanks :)
What model of phone are you using?
If it is indeed that the bluetooth connection is not persisting then you could try the following possible solutions:
Is there a setting on the phone to keep bluetooth on even when going into idle?
You could set the phone to not go into idle while your app is running, of course this is not ideal as it will cause battery drain.
Ok. After testing and testing several solutions (AlarmManager, BluetoothAdapter, etc...) I came to following conclusion:
Its not the Bluetooth connection that is lost, otherwise the SmartWatch 2 would lost connection with the Smartphone, and that never happens. In fact is the Phone CPU that is lost by the ControlExtension, because when the Smartphone idles the CPU also idles. By loosing the Phone CPU the ControlExtension cannot process the "sendText(...)" call and this means that the corresponding upper call "sendHostApp(...)" that uses the Bluetooth messages its also never called, that's why the TextView is not updated on the SmartWatch 2.
Also I think that when I touch the SmartWatch 2 screen, this triggers an hardware interruption that wake up the Phone CPU for short seconds to answer to the SmartWatch 2 Touch Event and thats why when I touch the SW2 screen the TextView is updated a few times before get stuck again.
This works fine for static Control Extension applications that only display static content and/or replies to the user (touch, swipe, etc...) events. But its a complete disaster for Control Extensions applications that need to be doing some processing regardless the user direct interaction.
I never though in this terms because I though that it was the job of the SmartConnect Host Application to guarantee Phone CPU to the Control Extensions.
So the solution for some apps could be using an AlartManager in order to schedule wake up calls to do some processing. For other apps the solution could be the PowerManger and use a wakelock.aquire()/wakelock.release().

Continues sound/vibration alerts for local notification while iphone is closed, as it is done in clock app

I wish to know how to generate local notification alerts similar to apple's clock alarm (that comes with the iPhone) while my application is the the background and/or the iPhone is closed. Currently I gets a single vibration and a single play of my ringtone. This is not sufficient and must run in loop till having user response. So how the did it in Apple? TNX.
They used private APIs that are not accessible to normal developers like you and I. The best you're going to get is that one ring and one vibration, unless you're not going for distribution in the App Store.

Background Audio and Remote Control Support using MPMusicPlayerController on iOS 4. Is this even possible?

I've spent two days on this and have gotten nowhere. I'm trying to use [MPMusicPlayerController applicationMusicPlayer] to play audio chosen from the user's iPod library and have it run in the background as well as support remote events. Now getting the music actually playing is the easy part. Get the instance, pick the songs, assign the music queue and play. Done and done. BUT... a) I can't get it to play in the background, and b) even when in the foreground I can't get the remote control events to work at all!
And before you ask, yes, I have set the plist entries, the audio session category, the call to say I'm interested in getting remote events and set up a first responder to listen for them, so please know, yes, I've read read every single document on the subject that I could find* (*a task I blame Apple for for not being clear at all on this topic, nor having ANY example code for it!) and I've watched every one of the WWDC videos relating to it (even freezing the screen to copy the code exactly from their example...) so unless I've missed something not in this list, replying with any of those answers is not going to help.
One more thing... I am explicitly talking about using the MPMusicPlayerController which according to the docs, never uses an application session. It always uses the system session. (Maybe that in itself answers my question, but the docs don't clearly say that so I'm not sure, hence this question.)
That said, after two days, my thoughts are this:
When using the MPMusicPlayerController, regardless of what methods you call or what plist entries you set, your app will never run in the background. Period. If you use the ipodMusicPlayer instance, the music keeps playing, but that's because it's the iPod that's playing, not your app. If you use the applicationMusicPlayer instance instead, when going to the background your music stops. In both cases, your app is suspended.
Regardless of your using the ipodMusicPlayer or applicationMusicPlayer instances, all remote events go to the iPod application itself, not yours, even if you've explicitly asked for them. If you are using the applicationMusicPlayer instance and you use the remote to select 'Play', the iPod app receives the command so your audio ducks out and is interrupted and playback begins in the iPod app. If you've chosen the ipodMusicPlayer instead, then of course it doesn't matter as you have explicitly said you're basically just interested in remotely controlling the iPod app which again, is what actually receives the remote events.
The icon in the quick-switch controls at the bottom never changes to your app's icon because again, your app is never actually set up to receive the events. The iPod application is, which is why its icon does appear there.
So what I want to know is... am I wrong here? Has anyone successfully been able to use MPMusicPlayerController and been able to intercept the remote events? While I'd prefer to use the applicationMusicPlayer with background music support so I don't muck with the user's iPod, the bigger thing is remote control notifications, meaning if I have to use the ipodMusicControl and keep my app in the foreground to intercept those messages, so be it. It's ugly that way, but at least it's something.
Code examples, or at least explicit steps against one of the built-in app templates would be GREATLY appreciated. (Don't even need the implementation... just the steps. Hopefully that will appease the inevitable 'It's still under NDA' thing that people keep answering questions with.)
Mark
I solved it. The info is in my other question over here...
Stack Overflow: Play iPod music while receiving remote control events
...but the short version is you have to use AVPlayer (but not AVAudioPlayer. No idea why that is!) with the asset URL from the MPMediaItem you got from the library, then set the audio session's category to Playable (do NOT enable mixable!) and add the appropriate keys to your info.plist file telling the OS your app wants to support background audio.
This lets you play items from your iPod library (except Audible.com files for some reason!) and still get remote events. Granted you have to do more work, and since this is your audio player which is separate from, and will interrupt the iPod app (which may or may not be desirable. And again, don't enable mixing or the iPod app will hijack the remote control events) but those are the breaks!
For anyone who wants to know, I found out to get the audio playing in the background, you have to set the audio session's category to Playable and then background audio works just fine. If you also want to play your own sounds at the same time, you have to mark the category as mixable. That solved the background music part. But what I've found out is any time the iPod is playing, it doesn't seem possible for you to get remote notifications.
Here's the updated thread...
How can you play music from the iPod app while still receiving remote control events in your app?
M

Resources