Nick_Zaillian wrote:
> Now, Mark, I have written an
> audio pattern playback implementation using a Handler that runs in my
> main Activity and, while it works, it is way less smooth and reliable
> than the implementation using the Timer/separate thread. 

That's not surprising. Depending on what else is going on, there may be
other messages in the message queue that the UI thread is working on, so
there may be a delay before your code gets to run.

> I tried to
> wade through the docs for AsyncTask and I could not tell whether or
> not it would allow me to update the UI from my separate Timer thread.

I listed that for completeness, but if you are trying to stick with
Timer, it's not really going to help.

> do I just have to choose between having smooth audio
> playback in a separate thread but no visual feedback and having less
> reliable audio playback in my UI thread with visual feedback?

I'd go for "smooth audio playback in a separate thread with slightly
delayed visual feedback in the UI thread" (i.e., your TimerTask does the
audio and invokes the View#post() for the UI update), but that's just
me, and I don't know your app.

If you want "smooth audio playback and simultaneous visual feedback", I
suspect the widget framework isn't the answer, and you'll need to roll
your own UI as if this were a game, using those sorts of techniques.

>From your follow-up post:

> "Thou shalt not modify the UI from a background thread, for that is
> the way of sin" pretty explicitly gives me my answer.

No. "Explicit" would have been if I had described what happens to
sinners. ;-)

> I gotta say, this is pretty inconvenient.

The widget framework isn't designed for your scenario, any more than it
is designed for 3D rendering. There are other tools for that.

> Must be the reason that Electrum Drum
> Machine (the only other Android drum sequencer I've seen) doesn't give
> the user any visual indication of playback position.

That's possible.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Android App Developer Books: http://commonsware.com/books.html

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to