Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Warning: audio error: Can't play because data is NULL
Started by davitzuroshvili Oct 31 2016 07:26 AM

- - - - -
1 reply to this topic
audio error

Best Answer bgmadclown , 31 October 2016 - 10:20 AM

I guess you need to change these lines

audio.play(backgroundMusicChannel)

to this

audio.play(backgroundMusic)

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

davitzuroshvili

[GLOBAL: userInfoPane.html]
davitzuroshvili
  • Enthusiast

  • 42 posts
  • Corona SDK

guys i have this error i cant fix  (title) 

my code:

-----------------------------------------------------------------------------------------
--
-- level1.lua
--
-----------------------------------------------------------------------------------------

local backgroundMusic = audio.loadStream("backgroundmusic.mp3")
local backgroundMusicChannel = audio.play( backgroundMusic, { channel=1, loops=-1, fadein=5000 }  )

local composer = require( "composer" )
local scene = composer.newScene()

-- include Corona's "physics" library
local physics = require "physics"
local widget = require "widget"
--------------------------------------------

-- forward declarations and other locals
local screenW, screenH, halfW = display.actualContentWidth, display.actualContentHeight, display.contentCenterX
local back



local function onbackRelease()
	
	-- go to level1.lua scene
	composer.gotoScene( "menu", "fade", 500 )
	
	return true	-- indicates successful touch
end
function scene:create( event )

	-- Called when the scene's view does not exist.
	-- 
	-- INSERT code here to initialize the scene
	-- e.g. add display objects to 'sceneGroup', add touch listeners, etc.

	local sceneGroup = self.view
	-- We need physics started to add bodies, but we don't want the simulaton
	-- running until the scene is on the screen.
	--physics.start()
	--physics.pause()

    audio.play(backgroundMusicChannel )
	-- create a grey rectangle as the backdrop
	-- the physical screen will likely be a different shape than our defined content area
	-- since we are going to position the background from it's top, left corner, draw the
	-- background at the real top, left corner.
	local background = display.newRect( display.screenOriginX, display.screenOriginY, screenW, screenH )
	background.anchorX = 0 
	background.anchorY = 0
	background:setFillColor( .5 )
	
	
    back = widget.newButton{
    	label="Back to menu",
		labelColor = { default={255}, over={128} },
		default="button.png",
		over="button-over.png",
		width=154, height=40,
		onRelease=onbackRelease
    }
    back.x=display.contentWidth-70
    back.y=display.contentHeight*0.1
	-- all display objects must be inserted into group
	sceneGroup:insert( background )
	sceneGroup:insert( back )
end


function scene:show( event )
	local sceneGroup = self.view
	local phase = event.phase
	
	if phase == "will" then
		-- Called when the scene is still off screen and is about to move on screen
	elseif phase == "did" then
		-- Called when the scene is now on screen
		-- 
		-- INSERT code here to make the scene come alive
		audio.play(backgroundMusicChannel)
		-- e.g. start timers, begin animation, play audio, etc.
		--audio.play(backgroundMusicChannel)
	end
end

function scene:hide( event )
	local sceneGroup = self.view
	
	local phase = event.phase
	
	if event.phase == "will" then
		-- Called when the scene is on screen and is about to move off screen
		--
		-- INSERT code here to pause the scene
		audio.stop({channel=backgroundMusicChannel})
		-- e.g. stop timers, stop animation, unload sounds, etc.)
	elseif phase == "did" then
		-- Called when the scene is now off screen
	end	
	
end

function scene:destroy( event )

	-- Called prior to the removal of scene's "view" (sceneGroup)
	-- 
	-- INSERT code here to cleanup the scene
	-- e.g. remove display objects, remove touch listeners, save state, etc.
	local sceneGroup = self.view
	
	package.loaded[physics] = nil
	physics = nil

	if back then
		back:removeSelf()	-- widgets must be manually removed
		back = nil
	end
end

---------------------------------------------------------------------------------

-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )

-----------------------------------------------------------------------------------------

return scene

help me please



[TOPIC: post.html]
#2

bgmadclown

[GLOBAL: userInfoPane.html]
bgmadclown
  • Contributor

  • 706 posts
  • Corona SDK

  Best Answer

I guess you need to change these lines

audio.play(backgroundMusicChannel)

to this

audio.play(backgroundMusic)



[topic_controls]
[/topic_controls]