Skip to content

Commit be9d708

Browse files
committed
[[ AndroidAudioRecorder ]] Don't automatically write to external storage
- Expect an absolute path to the record filename to be specified. - Remove automatic addition of 'WRITE_EXTERNAL_STORAGE' permission. - Modify the sample stack to write recording to external storage path
1 parent 41a0043 commit be9d708

2 files changed

Lines changed: 9 additions & 27 deletions

File tree

extensions/libraries/androidaudiorecorder/androidaudiorecorder.lcb

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ metadata title is "Android Audio Recorder"
1919

2020
-- We need permissions to record audio and write to the external
2121
-- storage directory.
22-
metadata android.permissions is "RECORD_AUDIO,WRITE_EXTERNAL_STORAGE,CAPTURE_AUDIO_OUTPUT"
22+
metadata android.permissions is "RECORD_AUDIO,CAPTURE_AUDIO_OUTPUT"
2323

2424
use com.livecode.foreign
2525
use com.livecode.java
@@ -44,11 +44,6 @@ __safe foreign handler _JNI_MediaRecorderReset(in pRecorder as JObject) returns
4444
binds to "java:android.media.MediaRecorder>reset()V"
4545
__safe foreign handler _JNI_MediaRecorderGetMaxAmplitude(in pRecorder as JObject) returns JInt \
4646
binds to "java:android.media.MediaRecorder>getMaxAmplitude()I"
47-
48-
__safe foreign handler _JNI_GetExternalStorageDir() returns JObject \
49-
binds to "java:android.os.Environment>getExternalStorageDirectory()Ljava/io/File;!static"
50-
__safe foreign handler _JNI_GetFilePath(in pFile as JObject) returns JString \
51-
binds to "java:java.io.File>getAbsolutePath()Ljava/lang/String;"
5247

5348
-- This will store an instance of a MediaRecorder
5449
private variable mRecorder as optional JObject
@@ -130,11 +125,14 @@ end handler
130125
Summary: Start recording an audio file, using the given filename
131126

132127
Example:
133-
androidRecorderStartRecording "recording.mp4"
128+
local tFilePath
129+
put specialFolderPath("external documents") & slash & "recording.mp4" \
130+
into tFilePath
131+
androidRecorderStartRecording tFilePath
134132

135133
Parameters:
136-
pFileName: The filename to use when recording audio
137-
134+
pFileName: The absolute filename of the output file
135+
138136
Description:
139137
Use the <androidRecorderStartRecording> handler to start recording audio
140138
on Android using the input source, compression type and output format
@@ -148,36 +146,20 @@ androidRecorderSetRecordInput (handler),
148146
androidRecorderSetRecordCompressionType (handler),
149147
androidRecorderSetRecordFormat (handler)
150148
*/
151-
public handler androidRecorderStartRecording(in pFileName as String) returns String
149+
public handler androidRecorderStartRecording(in pFileName as String) returns nothing
152150
if not IsAndroid() then
153151
throw "Not supported on this platform"
154152
end if
155-
-- Record an mp4 file in the external storage directory with the given
156-
-- name, (i.e. /storage/emulated/0/pFileName.mp4 or equivalent)
157153

158154
CreateRecorder()
159155

160156
if mRecorder is nothing then
161157
throw "unable to create recorder"
162158
end if
163159

164-
variable tFile as JString
165-
put GetAbsolutePathToPublicDocument(pFileName) into tFile
166-
_JNI_MediaRecorderSetRecordOutputFile(mRecorder, tFile)
160+
_JNI_MediaRecorderSetRecordOutputFile(mRecorder, StringToJString(pFileName))
167161
_JNI_MediaRecorderPrepare(mRecorder)
168162
_JNI_MediaRecorderStart(mRecorder)
169-
return StringFromJString(tFile)
170-
end handler
171-
172-
handler GetAbsolutePathToPublicDocument(in pDoc as String) returns JString
173-
variable tDirectory as JObject
174-
put _JNI_GetExternalStorageDir() into tDirectory
175-
176-
variable tPath as String
177-
put StringFromJString(_JNI_GetFilePath(tDirectory)) & "/" & pDoc into tPath
178-
variable tFile as JObject
179-
180-
return StringToJString(tPath)
181163
end handler
182164

183165
/**
188 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)