Hi guys,
Ok, I’ve been a member for a while, however I’ve only just started to pick up Corona - LOVING it.
I’m trying to make a simple video based app where you can play a couple of video clips from a main menu, so far this is working really well, HOWEVER, there are a couple of things I’m totally stuck on, and I’m really hoping that one of you experienced developers can help.
Basically, I have some music playing during the menu (I’ve commented it out in the code below), this plays well and works - woooohooooo, however, when I click on the button that takes you to a video it still plays the menu audio and the video clip audio at the same time.
Its like it needs to be cleaned out, cleared, or coded so when the buttons pressed it tells the music to stop (say, put a 1 somewhere to indicate the video is playing, and when complete change back to 0 so the menu audio starts again) - however, even though I have an idea of how this could possibly be the case, I cant for the life of me figure it out.
I’ve put the code below, and if anyone can help I would REALLY appreciate it.
Cheers all and thank you for the time looking into this for me, hopefully its something easy and obvious.
Chris
– Decalre the visible width and height of the screen as constrants
_W = display.viewableContentWidth
_H = display.viewableContentHeight
– Turns OFF status bar —
display.setStatusBar(display.HiddenStatusBar)
– background audio - however this plays even when the video is playing, need to fix before turning it on –
–backgroundMusic = audio.loadStream(“theme.mp3”)
–backgroundMusicChannel = audio.play( backgroundMusic, { channel=1, loops=-0, fadein=1000 } ) – play the background music on channel 1, loop infinitely, and fadein over 5 seconds
–local background = display.newRect(0,0,_W, _H)
–background:setFillColour(255,255,255)
– background image –
local bg = display.newImageRect(“bg.jpg”,512,490)
bg.x = display.contentWidth/2
bg.y = display.contentHeight/2
—web link —
local startButton = display.newImageRect(“website.png”, 50, 50)
startButton.x=450
startButton.y=250
function startButton:tap(event)
system.openURL( “http://www.website.com/uk/”) – open URL in browser
end
startButton:addEventListener(“tap”, startButton)
– web link —
local startButton1 = display.newImageRect(“youtube.jpg”, 100, 20)
startButton1.x=360
startButton1.y=263
function startButton1:tap(event)
system.openURL( “http://www.youtube.com”) – open URL in browser
end
startButton1:addEventListener(“tap”, startButton1)
– sets up buttons –
local Button = {};
Button.new = function(params)
local btn = display.newGroup();
local offIMG = params and params.off or “”;
local onIMG = params and params.on or “”;
local off = display.newImageRect(offIMG, 100, 100);
local on = display.newImageRect(onIMG, 100, 100);
on.alpha = 0;
btn:insert(off);
btn:insert(on);
btn.x = params and params.x or 0;
btn.y = params and params.y or 0;
function btn:touch(e)
if(e.phase == “began”) then
on.alpha = 1;
display.getCurrentStage():setFocus(self)
self.hasFocus = true;
elseif(self.hasFocus) then
if(e.phase == “ended”) then
– Execute the callback function, if present
if(params) then
if(params.callback) then
params.callback(e);
end
end
on.alpha = 0;
display.getCurrentStage():setFocus(nil);
self.hasFocus = false;
end
end
end
btn:addEventListener(“touch”,btn);
return btn;
end – end Button class declaration
local Button2 = {};
Button.new = function(params)
local btn = display.newGroup();
local offIMG = params and params.off or “”;
local onIMG = params and params.on or “”;
local off = display.newImageRect(offIMG, 200, 30);
local on = display.newImageRect(onIMG, 200, 30);
on.alpha = 0;
btn:insert(off);
btn:insert(on);
btn.x = params and params.x or 0;
btn.y = params and params.y or 0;
function btn:touch(e)
if(e.phase == “began”) then
on.alpha = 1;
display.getCurrentStage():setFocus(self)
self.hasFocus = true;
elseif(self.hasFocus) then
if(e.phase == “ended”) then
– Execute the callback function, if present
if(params) then
if(params.callback) then
params.callback(e);
end
end
on.alpha = 0;
display.getCurrentStage():setFocus(nil);
self.hasFocus = false;
end
end
end
btn:addEventListener(“touch”,btn);
return btn;
end – end Button class declaration
– BUTTON 1 —
local videoButton = Button.new({
off = “images/lighthousev2_ON.png”,
on = “images/lighthousev2_OFF.png”,
x = 396,
y = 125,
callback = function(e)
media.playVideo(“lighthouse.mp4”,true,function(e)
print(“video ended”);
end)
end
})
– BUTTON 2 —
local videoButton = Button.new({
off = “images/kingrv2_ON.png”,
on = “images/kingrv2_OFF.png”,
x = 396,
y = 165,
callback = function(e)
media.playVideo(“king.mp4”,true,function(e)
print(“video ended”);
end)
end
})
– BUTTON 3 —
local videoButton = Button.new({
off = “images/monsterv2_ON.png”,
on = “images/monsterv2_OFF.png”,
x = 396,
y = 205,
callback = function(e)
media.playVideo(“monster.mp4”,true,function(e)
print(“video ended”);
end)
end
})
[import]uid: 43642 topic_id: 36686 reply_id: 336686[/import]