I have made my coding But now i wonder how can I save my audio file that i have recorded.How can we do that?can somebody help me please?
[code]
module(…, package.seeall)
function new()
local localGroup = display.newGroup()
local ui = require(“ui”)
local r
local recButton
local status = false
local bgimage = display.newImageRect(“background2.jpg”,1024,768)
bgimage.x = 512
bgimage.y = 384
localGroup:insert(bgimage)
local isAndroid = “Android” == system.getInfo(“platformName”)
local isXcodeSimulator = “iPhone Simulator” == system.getInfo(“model”)
if(isAndroid or isXcodeSimulator) then
local alert = native.showAlert( “Information”, “Camera API not available on Android or iOS Simulator.”, { “OK”})
end
local dataFileName = “testfile”
if “simulator” == system.getInfo(“environment”) then
dataFileName = dataFileName … “.wav”
else
local platformName = system.getInfo( “platformName” )
if “iPhone OS” == platformName then
dataFileName = dataFileName … “.wav”
elseif “Android” == platformName then
dataFileName = dataFileName … “.pcm”
else
print("Unknown OS " … platformName )
end
end
print (dataFileName)
local text = ui.newLabel{
bounds = { 350, 610, 300, 40 },
text = “Take a Picture”,
font = system.defaultFont,
textColor = {255 , 255,255, 255 },
size = 25,
align = “center”
}
local btn = display.newRoundedRect( 400, 600,200,50,16)
btn:setFillColor( 0, 0, 0,125 )
local sessionComplete = function(event)
local image = event.target
print( "Camera ", ( image and “returned an image” ) or “session was cancelled” )
print( "event name: " … event.name )
print( "target: " … tostring( image ) )
if image then
image.x = display.contentWidth/2
image.y = display.contentHeight/2
local w = image.width
local h = image.height
print( “w,h = “… w …”,” … h )
end
end
local listener = function( event )
media.show( media.Camera, sessionComplete )
return true
end
btn:addEventListener( “tap”, listener )
local s = ui.newLabel{
bounds = { 350, 530, 300, 40 },
text = " ",
textColor = { 255,255 , 255, 255 },
size = 32,
align = “center”
}
local roundedRect = display.newRoundedRect( 397, 522, 200, 50, 8 )
roundedRect:setFillColor( 0, 0, 0, 170 )
local function updateStatus ()
local statusText = " "
if r then
local recString = “”
local fRecording = r:isRecording ()
if fRecording then
recString = “Recording”
else
recString = “Idle”
end
statusText = recString
end
s:setText (statusText)
end
local function update ()
local statusText = " "
if r then
local recString = “”
if fSoundPlaying then
recString = “Playing”
elseif fSoundPaused then
recString = “Paused”
else
recString = “Idle”
end
statusText = recString
end
s:setText (statusText)
end
local function recButtonPress ( event )
if r then
if r:isRecording () then
local rec=display.newImage(“rec.png”)
rec.x=330
rec.y=545
r:stopRecording()
local filePath = system.pathForFile( dataFileName, system.DocumentsDirectory )
local file = io.open( filePath, “r” )
if file then
io.close( file )
fSoundPlaying = false
fSoundPaused = false
playbackSoundHandle = audio.loadStream( dataFileName, system.DocumentsDirectory )
end
else
fSoundPlaying = false
fSoundPaused = false
local rec=display.newImage(“recstop.png”)
rec.x=330
rec.y=545
audio.dispose(playbackSoundHandle)
r:startRecording()
end
end
updateStatus ()
end
local fSoundPlaying = false
local fSoundPaused = false
local function playButtonPress(event)
audio.play( playbackSoundHandle )
fSoundPlaying = true
fSoundPaused = false
update ()
end
recButton = ui.newButton{
default = “rec.png”,
over = “rec.png”,
onPress = recButtonPress,
emboss = true
}
recButton.x = 330
recButton.y = 545
playButton = ui.newButton{
default = “play.png”,
over = “play.png”,
onPress = playButtonPress,
emboss = true
}
playButton.x = 670
playButton.y = 545
local filePath = system.pathForFile( dataFileName, system.DocumentsDirectory )
r = media.newRecording(filePath)
updateStatus ()
return localGroup
end
[/code] [import]uid: 82446 topic_id: 16992 reply_id: 316992[/import]