Record and Play sound at same time IOS
Stephen MacLean
smaclean at madmansoft.com
Sat Apr 26 22:31:23 EDT 2014
T'was fun:) And since I'd just spent a bunch of time building recording and playback into my app, it was pretty fresh.
Running in the iOS simulator, you can see what's being written to the cache (Your user account > Library > Application Support > iPhone Simulator > the os version you are running on the simulator > The UUID of your app > Library > Caches).
While the file was created when I started recording, by watching the file I could see that it wasn't growing in size until I stopped recording. Which meant data wasn't being dumped to until then. So while there was a file to play, there was no data to be played.
Best,
Steve
On Apr 26, 2014, at 10:18 PM, Nakia Brewer <Nakia.Brewer at westrac.com.au> wrote:
> Thanks mate,
>
> Will give this a crack!
>
> Btw, how did you come to the assumption the file was not being written to real time ?
>
> In my testing I could start playing the file whilst I was still recording it which indicated to me it was being written real time.
>
> Sent from my iPhone
>
>> On 27 Apr 2014, at 12:12 pm, "Stephen MacLean" <smaclean at madmansoft.com> wrote:
>>
>> Hi Nakia,
>>
>> Ok, played around some, and found that while the file is created when you start to record, it doesn't write any data to it until you stop recording. That's not going to work, so I came up with a little something that does. It rotates the file that is being recorded and the file that is playing. Works pretty good, lol, but there sometimes a slight pop when switching files. Your milage may vary!
>>
>> See what you think. It was an interesting exercise!
>>
>> Put 2 buttons on a card. Name one Record and the other Stop
>>
>> Out this into the script of the Record button:
>>
>> global gFileNamePath1,gFileNamePath2,gFileNamePath3
>> global gRecFileName1,gRecFileName2,gRecFileName3
>> global gRecPointer1,gRecPointer2,gRecPointer3
>> global gCurrentFileNum
>> global gSendJammerID
>>
>> on mouseUp
>> #Setup mergMicrophone
>> if the environment is "mobile" then
>> mergMicrophoneSetNumberOfChannels "Stereo"
>> mergMicrophoneSetSampleRate 44100
>> mergMicrophoneSetAudioFormat "MP4-AAC"
>> mergMicrophoneSetTargetBitRate 65536
>> mergMicrophoneSetAudioQuality "High"
>> end if
>>
>> # Setup up AV Session
>> if the environment is "mobile" then
>> mergAVAudioSessionSetCategory "play and record",false,false,true,true
>> end if
>>
>> # Setup file names & current file number
>> put UUID ("random") into tUUID1
>> put UUID ("random") into tUUID2
>> put UUID ("random") into tUUID3
>> put 1 into gCurrentFileNum
>> if the environment is "mobile" then
>> put specialFolderPath("cache") & slash & tUUID1 & ".m4a" into gFileNamePath1
>> put specialFolderPath("cache") & slash & tUUID2 & ".m4a" into gFileNamePath2
>> put specialFolderPath("cache") & slash & tUUID3 & ".m4a" into gFileNamePath3
>> put tUUID1 & ".m4a" into gRecFileName1
>> put tUUID2 & ".m4a" into gRecFileName2
>> put tUUID3 & ".m4a" into gRecFileName3
>> # Start Recording with file 1
>> mergMicrophoneStartRecording gFileNamePath1
>> send "playBackJammerStream" to me in 500 millisec
>> put the result into gSendJammerID # To cancel sends when stop is pressed
>> end if
>> end mouseUp
>>
>> on playBackJammerStream
>> #stop recording current file, start recording on next, start playing current file
>> switch gCurrentFileNum
>> case 1
>> mergMicrophoneStopRecording # Stop recording to current file so data is written to disk
>> mergMicrophoneStartRecording gFileNamePath2 # Start recording to new file so you don't lose anything in the stream
>> put "file:" & gFileNamePath1 into tGetFile # Set up file we just stopped recording for playback
>> put mergAVPlayerCreateFromURL (tGetFile) into gRecPointer1 # Create the AV player for that file
>> mergAVPlayerDo gRecPointer1,"play" # Start playing file
>> put 2 into gCurrentFileNum # Advance counter for next callback
>> send "playBackJammerStream" to me in 500 millisec # Call me back to do all over again
>> put the result into gSendJammerID # To cancel sends when stop is pressed
>> break
>> case 2
>> mergMicrophoneStopRecording
>> mergMicrophoneStartRecording gFileNamePath3
>> put "file:" & gFileNamePath2 into tGetFile
>> put mergAVPlayerCreateFromURL (tGetFile) into gRecPointer2
>> mergAVPlayerDo gRecPointer2,"play"
>> put 3 into gCurrentFileNum
>> send "playBackJammerStream" to me in 500 millisec
>> put the result into gSendJammerID # To cancel sends when stop is pressed
>> break
>> case 3
>> mergMicrophoneStopRecording
>> mergMicrophoneStartRecording gFileNamePath1
>> put "file:" & gFileNamePath3 into tGetFile
>> put mergAVPlayerCreateFromURL (tGetFile) into gRecPointer3
>> mergAVPlayerDo gRecPointer3,"play"
>> put 1 into gCurrentFileNum
>> send "playBackJammerStream" to me in 500 millisec
>> put the result into gSendJammerID # To cancel sends when stop is pressed
>> break
>> end switch
>> end playBackJammerStream
>>
>> and put this into the Stop button:
>>
>> global gSendJammerID
>>
>> on mouseUp
>> # Stop recording and cancel the send timer
>> if the environment is "mobile" then
>> mergMicrophoneStopRecording
>> cancel gSendJammerID
>> end if
>> end mouseUp
>>
>> Best,
>>
>> Steve
>>
>>> On Apr 26, 2014, at 7:29 PM, Nakia Brewer <Nakia.Brewer at westrac.com.au> wrote:
>>>
>>> Ah righto, that might explain why I cant get it to work.
>>>
>>> I am pretty sure the file is being written real time from mergMicrophone as I can play the file using the other methods and it plays up to its current location when I called the play command (I am calling the play whilst I am still recording)..
>>>
>>> It seems like LiveCode only evaluates the file on the initial play command and doesn't re evaluate the file whilst it playing hence only playing up to the duration that existed on the initial play command call...
>>>
>>> As I am only playing audio do I need to even have a UI for the player? I have tried setting the visible of the player to false but still nothing played.
>>>
>>> Thanks for taking a look at it, I appreciate it!
>>
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>
> COPYRIGHT / DISCLAIMER: This message and/or including attached files may contain confidential proprietary or privileged information. If you are not the intended recipient, you are strictly prohibited from using, reproducing, disclosing or distributing the information contained in this email without authorisation from WesTrac. If you have received this message in error please contact WesTrac on +61 8 9377 9444. We do not accept liability in connection with computer virus, data corruption, delay, interruption, unauthorised access or unauthorised amendment. We reserve the right to monitor all e-mail communications.
>
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list