Hi there! I need help with retrieving a recorded audio file from system.DocumentsDirectory in my code. I record an audio file in corona, then I save it to system.DocumentsDirectory. I need to access this audio file within a OneSignal push notification Post.
The audio is recorded and plays back fine. But when the push notification is called when i press btn3, the notification appears but without the recorded audio file that should play.
All help is appreciated thanks!
code below:
[lua]
– Your code here
local OneSignal = require(“plugin.OneSignal”)
– This function gets called when the user opens a notification or one is received when the app is open and active.
– Change the code below to fit your app’s needs.
function DidReceiveRemoteNotification(message, additionalData, isActive)
if (additionalData) then
if (additionalData.discount) then
native.showAlert( “Discount!”, message, { “OK” } )
– Take user to your app store
elseif (additionalData.actionSelected) then – Interactive notification button pressed
native.showAlert(“Button Pressed!”, “ButtonID:” … additionalData.actionSelected, { “OK”} )
end
else
native.showAlert(“OneSignal Message”, message, { “OK” } )
end
end
OneSignal.Init(“MY ONE SIGNAL ID GOES HERE”, “############”, DidReceiveRemoteNotification)
– Creates a notification to be deliver to this device as a test.
function IdsAvailable(userID, pushToken)
if (pushToken) then
local notification = {
[“contents”] = {[“en”] = “This is a Test notification! HI MAX!!”, [“ios_sound”] = “newRecording.aif”}
}
notification[“include_player_ids”] = {userID}
OneSignal.PostNotification(notification)
end
end
local bg = display.newRect(display.contentCenterX, display.contentCenterY, 1000, 1000)
local btn1 = display.newCircle(display.contentCenterX, display.contentCenterY, 50)
btn1:setFillColor(1, 0, 0)
local btn2 = display.newCircle(display.contentCenterX, display.contentCenterY - 150, 50)
btn2:setFillColor(0, 1, 0)
local btn3 = display.newCircle(display.contentCenterX, display.contentCenterY + 150, 50)
btn3:setFillColor(0, 0, 1)
local function startRecording(event)
if (event.phase == “began”) then
local filePath = system.pathForFile( “newRecording.aif”, system.DocumentsDirectory )
local recording = media.newRecording( filePath )
recording:startRecording()
end
end
local function stopRecording(event)
if (event.phase == “began”) then
local filePath = system.pathForFile( “newRecording.aif”, system.DocumentsDirectory)
local recording = media.newRecording( filePath )
recording:stopRecording()
local sound = audio.loadSound(“newRecording.aif”, system.DocumentsDirectory )
audio.play(sound)
end
end
local function sendRecording(event)
if (event.phase == “began”) then
OneSignal.IdsAvailableCallback(IdsAvailable)
end
end
btn3:addEventListener(“touch”, sendRecording)
btn2:addEventListener(“touch”, startRecording )
btn1:addEventListener(“touch”, stopRecording ) [/lua]