Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Audio doesn't play after 85 previous reproductions
Started by josepanton Oct 29 2018 12:56 AM

1 reply to this topic
loadstream audio audio.play audio.loadstream
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

josepanton

[GLOBAL: userInfoPane.html]
josepanton
  • Observer

  • 2 posts
  • Corona SDK

Hi,

 

I have a project to learn English and I'm problems with audio.
In quiz scene, I like play an audio in order to users can listen a phrase in every quiz. This works fine until the first 85 reproductions, but the next audio reproduction doesn't work, I haven't any error on console, but Corona don't execute audio.play because don't enter into complete listener.
 
I tried isolate this part of code but with the same results.
 

 

This is the code:
 
local composer = require( "composer" )


local unidad = 5
local test = 1
local contador = 1
local continuar = true
local fallo = false
local totalFallos = 0
local tm

local scene = composer.newScene()


function scene:create( event )
	local sceneGroup = self.view
end

function scene:show( event )
	local sceneGroup = self.view
	local phase = event.phase
	
	if phase == "will" then
		local lblNumQuiz = display.newText( sceneGroup, "Unidad: " .. unidad .. " - Test: " .. test, 160, 80 , native.systemFont , 18 )
		local lblactual = display.newText( sceneGroup, "contador actual: " .. contador, 160, 200 , native.systemFont , 18 )

		local function esperar( )
			lblNumQuiz.text = "Unidad: " .. unidad .. " - Test: " .. test
			lblactual.text = "contador actual: " .. contador
			local function networkListener( event )
			    if ( event.isError ) then
			        print( "Network error - download failed: ", event.response )
			    elseif ( event.phase == "began" ) then
			        print( "Progress Phase: began" )
			    elseif ( event.phase == "ended" ) then
			    	local function lstnFinalizado (event)
			    		if event.completed then
				    		print("Se ha reproducido correctamente el audio")
				    		isReproducido = false
				    		audio.dispose( ficheroAudio )
				    		ficheroAudio = nil
				    		audioChannel = nil
				    	else
				    		print("No se ha completado el audio")
				    		isReproducido = false
				    	end
			    	end
			        print( "Archivo descargado" )
			       	local ficheroAudio = audio.loadStream("audio" .. contador .. ".mp3", system.DocumentsDirectory)
			       	if ficheroAudio == nil then 
			       		print("No se ha podido descargar el fichero") 
			       		audio.play( koSound, { channel=1 } )
			       		fallo = true
			       		totalFallos = totalFallos + 1
			       	else
						local audioChannel = audio.play(ficheroAudio ,{ channel=3, onComplete=lstnFinalizado })
						totalFallos = 0
					end
					if fallo then
						test = 1
						unidad = unidad + 1
						fallo = false
						if totalFallos == 2 then 
							local lblfinal = display.newText( sceneGroup, "contador final: " .. contador, 160, 400 , native.systemFont , 18 )
							timer.cancel( tm )
						end
					else
						test = test + 1
					end
					contador = contador + 1
				end
			end
			 
			local params = {}
			params.progress = true
			 
			network.download(
			    "https://SERVERURL/audio/" .. unidad .. "_" .. test .. ".mp3",
			    "GET",
			    networkListener,
			    params,
			    "audio" .. contador .. ".mp3"
			)
		end
		tm = timer.performWithDelay( 8000, esperar, 1000 )

			

	elseif phase == "did" then

	end	
end
			        	
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
 
return scene

Any idea to solve this problem?

 

 

 

 

Attached Files



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 293 posts
  • Corona SDK

"..I haven't any error on console.."

 

The console log that you posted seems to state that your problem probably lies with "audio78.mp3". If the audio files have successfully run on previous levels with the same code, then it is possible that audio78.mp3 file is missing completely, there may be a typo in its name or you don't load the file like you do all the others.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: loadstream, audio, audio.play, audio.loadstream