updating the ui from thread using audiotrack
I've an app that records audio using audiorecord and audiotrack to play. I've a progressbar in the ui that needs to increment as the track plays. The audiotrack api says that the read and write methods are blocking. These means that the ui is frozen till the write finishes, which is no good for the progressbar. I've looked at both audiorrack modes static and stream but both are blocking. Is there a way to update the ui whilst streaming or writing th开发者_高级运维e audiotrack?
Thanks mat
Using AsyncTask would be one of the easiest.
It is important you move as much processing to background threads as possible. The main reason is that your app doesn't respond to a ui request within 5 sec, android will give the user the dreaded 'force close' screen. See AsyncTask for the easiest way to do this. Just make sure that you put any code that updates the ui into the onProgressUpdate portion of AsyncTask. If you choose to thread in an alternative way, using runOnUiThread will solve that.
精彩评论