S SDFP Studio Member Licensed User Jan 30, 2021 #1 Hello, I have a long process (audio decoding) which can take 30 or more seconds to execute, it is inline java code. When i call my function it freeze app during execution (so 30 or more seconds). Is there a solution to do that in background. Tried thread.RunOnGuiThread but does not execute in background, it freeze app, maybe i don't use it as i should. Tried thread.start but nothing happens. If i understand, Erel seems to say that we should not use threads but resumable subs. So what can i do in such a case ? Thank you
Hello, I have a long process (audio decoding) which can take 30 or more seconds to execute, it is inline java code. When i call my function it freeze app during execution (so 30 or more seconds). Is there a solution to do that in background. Tried thread.RunOnGuiThread but does not execute in background, it freeze app, maybe i don't use it as i should. Tried thread.start but nothing happens. If i understand, Erel seems to say that we should not use threads but resumable subs. So what can i do in such a case ? Thank you
Erel B4X founder Staff member Licensed User Longtime User Jan 31, 2021 #2 SDFP Studio said: I have a long process (audio decoding) which can take 30 or more seconds to execute, it is inline java code. Click to expand... Can you post the code? What is it doing that takes so long? Upvote 0
SDFP Studio said: I have a long process (audio decoding) which can take 30 or more seconds to execute, it is inline java code. Click to expand... Can you post the code? What is it doing that takes so long?
S SDFP Studio Member Licensed User Jan 31, 2021 #3 I use MediaExtractor and MediaCodec to extract the decoded audio from the audio or video, do some calculations and write it to a file. Media are 3 minutes to 1 hour long, so it takes time. I started reading your post Libraries and multithreading but it is 'high level' for me so i'm studying it. Thanks to you and sfsameer for your help. Upvote 0
I use MediaExtractor and MediaCodec to extract the decoded audio from the audio or video, do some calculations and write it to a file. Media are 3 minutes to 1 hour long, so it takes time. I started reading your post Libraries and multithreading but it is 'high level' for me so i'm studying it. Thanks to you and sfsameer for your help.
Erel B4X founder Staff member Licensed User Longtime User Jan 31, 2021 #4 Which step is the slow one? The calcuations you are doing? As it is done with inline Java, you do need to use runAsync. Example: https://www.b4x.com/android/forum/threads/advertising-id.101050/#content Upvote 0
Which step is the slow one? The calcuations you are doing? As it is done with inline Java, you do need to use runAsync. Example: https://www.b4x.com/android/forum/threads/advertising-id.101050/#content
S SDFP Studio Member Licensed User Jan 31, 2021 #5 The calculation is very simple, it is an average of the audio samples but: for 1 min of 44.1 KHz stereo audio, there are 44100 * 2 tracks + 2 bytes (16bits audio) * 60s = 10,584,000 bytes, then i'm writing to a file (far less data) so i'm not surprised it takes a long time. I use runAsync and and it's magic, works fine in the background with no effect on the UI, it's perfect Thank you Upvote 0
The calculation is very simple, it is an average of the audio samples but: for 1 min of 44.1 KHz stereo audio, there are 44100 * 2 tracks + 2 bytes (16bits audio) * 60s = 10,584,000 bytes, then i'm writing to a file (far less data) so i'm not surprised it takes a long time. I use runAsync and and it's magic, works fine in the background with no effect on the UI, it's perfect Thank you