I click a button to start music playing and then click to make it pause – when I click Play again I receive the following message in the terminal (and the sound does not start playing again):
Warning: audio error: Can’t play shared streamed sample because it is already in use
The code I’m using is below – can you spot what I’ve done wrong?
Jay
display.setStatusBar(display.HiddenStatusBar) local widget = require("widget") audio.reserveChannels( 1 ) sndChanMusic = 1 local sndMusic = audio.loadStream ( "audio/electrohouse.wav" ) local function buttonHit(event) local action = event.target.id if action == "play" then event.target:setLabel("Pause") event.target.id = "pause" audio.play(sndMusic, {channel=sndChanMusic} ) elseif action == "pause" then event.target:setLabel("Play") event.target.id = "play" audio.pause ( sndChanMusic ) end end local btn = widget.newButton { label="Play", id = "play", fontSize = 30, defaultFile = "images/buttonDefault.png", overFile = "images/buttonSelected.png", onRelease=buttonHit, } btn.x = display.contentCenterX btn.y = display.contentCenterY