--[[
ģƣ¼
ģ鹦ܣ¼ܡȡ¼Լ¼
ģ޸ʱ䣺2017.04.05
]]

module(...,package.seeall)
require"record"

--ÿζȡ¼ļ
local RCD_READ_UNIT = 1024
--rcdoffsetǰȡ¼ļʼλ
--rcdsize¼ļܳ
--rcdcntǰҪȡٴ¼ļȫȡ
local rcdoffset,rcdsize,rcdcnt



--[[
print
  ӡӿڣļедӡtestǰ׺
  
ֵ
]]
local function print(...)
	_G.print("test",...)
end

--[[
playcb
  ¼Ļص
  
ֵ
]]
local function playcb(r)
	print("playcb",r)
	--ɾ¼ļ
	record.delete()
end

--[[
readrcd
  ȡ¼ļ
  
ֵ
]]
local function readrcd()	
	local s = record.getdata(rcdoffset,RCD_READ_UNIT)
	print("readrcd",rcdoffset,rcdcnt,string.len(s))
	rcdcnt = rcdcnt-1
	--¼ļѾȫȡ
	if rcdcnt<=0 then
		sys.timer_stop(readrcd)
		--¼
		audio.play(0,"RECORD",record.getfilepath(),audiocore.VOL7,playcb)
	--ûȫȡ
	else
		rcdoffset = rcdoffset+RCD_READ_UNIT
	end
end

--[[
rcdcb
  ¼Ļص
  
		result¼trueʾɹfalsenilʾʧ
		sizenumberͣ¼ļĴСλֽڣresultΪtrueʱ
ֵ
]]
local function rcdcb(result,size)
	print("rcdcb",result,size)
	if result then
		rcdoffset,rcdsize,rcdcnt = 0,size,(size-1)/RCD_READ_UNIT+1
		sys.timer_loop_start(readrcd,1000)
	end	
end

--5󣬿ʼ¼
sys.timer_start(record.start,5000,5,rcdcb)
