Can ActionScript Workers be used to play / generate Sounds in a separate thread?

余生颓废 提交于 2019-12-10 10:35:58

问题


I'm very new to ActionScript Workers, but I would like to know if this is possible.

From what I have read, ActionScript Workers (ASW) are like separate threads that can do more CPU intensive calculations without interrupting the Main thread (which is executing your main SWF file).

The only example I really seen kicking around was the one illustrating animation playing at a consistent rate while an ASW took care of loading or calculating some intensive math formulas.

Is the Sound API available for ActionScriptWorkers?


回答1:


(Reposted under my proper login)

They certainly can! Check out my recent blog post on exactly this:

http://flexmonkey.blogspot.co.uk/2012/09/multi-threaded-sound-synthesis-in-flex.html#!/2012/09/multi-threaded-sound-synthesis-in-flex.html

After a fair bit of tinkering, I actually generate a byte array in a background worker and then write the data back to the SampleDataEvent's data property in the primordial thread (i.e. the user interface).

I write the data from the worker from the previous SampleDataEvent while the worker generates the data for the next one - so FlashPlayer is actually doing three tasks simultaneously: offering a responsive UI, playing a tone and generating the next tone.

simon




回答2:


I'm going to venture out onto a cliff and answer YES to this question.

The release notes has a list of "non-functional" API's, I don't see any sound related classes in the list.

The following APIs will not be available from within a background worker. Any attempt to construct an instance of any of these will throw an IllegalOperationError with the message "This feature is not available within this context," the errorID will be the same in all instances, allowing developers to key off of this value.

  • flash.desktop.Clipboard // calling constructor will throw; calling generalClipboard will return null
  • flash.desktop.NativeDragManager // isSupported returns false
  • flash.desktop.Updater // isSupported returns false
  • flash.display.NativeMenu // isSupported returns false
  • flash.display.NativeWindow // isSupported returns false
  • flash.display.ToastWindow // can't access instance because stage.window will never be defined
  • flash.display.Window // can't access instance because stage.window will never be defined
  • flash.external.ExtensionContext // createExtensionContext() will always return null or throw an error
  • flash.external.ExternalInterface // available returns false
  • flash.html.* // HTMLLoader.isSupported returns false
  • flash.media.CameraRoll // supportsAddBitmapData and supportsBrowseForImage returns false
  • flash.media.CameraUI // isSupported returns false
  • flash.media.StageWebView // isSupported returns false
  • flash.net.drm.* // DRMManager.isSupported returns false
  • flash.printing.* // PrintJob.isSupported returns false
  • flash.security.XMLSignatureValidator // isSupported returns false
  • flash.system.IME // isSupported returns false
  • flash.system.SystemUpdater // calling constructor throws
  • flash.text.StageText // calling constructor throws flash.ui.ContextMenu // isSupported returns false
  • flash.ui.GameInput // isSupported returns false
  • flash.ui.Mouse // all methods are no-ops; setting 'cursor' property is a no-op


来源:https://stackoverflow.com/questions/11902863/can-actionscript-workers-be-used-to-play-generate-sounds-in-a-separate-thread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!