I have an app in which records audio files. User can specify length of recorded audio, number of samples and time between recordings. For example:
length = 3 sec
samples = 2
interval = 5 sec
When app starts it creates a thread, waits 5 seconds and creates second thread.
First thread records 3 seconds sample to a specified directory.
After 2 seconds, next thread starts recording second sample. It works and creates two files: sample1.3gp, sample2.3gp.
But when user specify:
length = 3 sec
samples = 2
interval = 1 sec
recording cannot be done because of 2nd thread try to access to media recorder when 1st thread still uses it.
I want to be able to set some lock for that resource. What I mean ?
When 1st thread starts 3 seconds recording, after 1 second 2nd thread tries to record too.
But it should wait next two seconds until 1st thread finishes its job.
What is the best way to solve that problem ?