video playback completion event not working, Need help!

Hi guys m facing a little trouble while going back to the page after completion of video playback. In my application video is playing nicely but after completion video starts playing again.
I want to go back to previous screen on video complete, i dont know what i am doing wrong. Need your help guys!

Thanks in advance.

–My code here

local function onComplete()
director:changeScene(“page01”, “fade” )
end

local function playVideo(event)
media.playVideo( “video.mp4”, true, onComplete )
end [import]uid: 83799 topic_id: 26442 reply_id: 326442[/import]

That should work…

Maybe adding a insignificant delay will help:

local function onComplete()  
 print("video playback complete") -- if this doesn't fire then something is wrong  
 local function delay()  
 director:changeScene("page01", "fade" )  
 end  
  
 timer.performWithDelay(2, delay)  
end  
  
local function playVideo(event)  
 media.playVideo( "video.mp4", true, onComplete )  
end  

[import]uid: 84637 topic_id: 26442 reply_id: 107287[/import]

Thanks Denny…

print(“video playback complete”) is not getting fire in terminal window. I will still try to run a built on device…
I am creating app for “sony s tablet…”

here is my full code for the page01

module(…, package.seeall)

function new()
local localGroup = display.newGroup()

local page01bg = display.newImage(“images/pagebg.png”)
localGroup:insert(page01bg)

local pg01text01 = display.newImage(“images/pg01text01.png”)
pg01text01.x = 280 ; pg01text01.y = 180
localGroup:insert(pg01text01)

local pg01text02 = display.newImage(“images/pg01text02.png”)
pg01text02.x = 740 ; pg01text02.y = 530
localGroup:insert(pg01text02)

local forwardbtn = display.newImage(“images/forwardbtn.png”)
forwardbtn:setReferencePoint(display.CenterReferencePoint)
forwardbtn.x = _W - 40; forwardbtn.y = _H - 40
localGroup:insert(forwardbtn)

local function pressforward(event)
if event.phase == “ended” and btnIsActive == “true” then
director:changeScene(“page02”, “fade” )
print(“Going to page 02!”)
end
end

local pg01img01 = display.newImage(“images/pg01img01.png”)
pg01img01:setReferencePoint(display.TopRightReferencePoint)
pg01img01.x = _W - 40; pg01img01.y = 40
pg01img01.xScale = 0.5 ; pg01img01.yScale = 0.5
localGroup:insert(pg01img01)

local pg02img02 = display.newImage(“images/pg02img02.png”)
pg02img02:setReferencePoint(display.BottomLeftReferencePoint)
pg02img02.x = 40; pg02img02.y = _H - 100
pg02img02.xScale = 0.5 ; pg02img02.yScale = 0.5
–pg02img02.alpha = 0.2
localGroup:insert(pg02img02)

local function spawnpopup01 (event)
if btnIsActive == “true” then
local popup01 = display.newImage(“images/pg01img01.png”)
popup01:setReferencePoint(display.CenterReferencePoint)
popup01.x = _W /2; popup01.y = _H /2 - 30
popup01.xScale = 0.5 ; popup01.yScale = 0.5
popup01.alpha = 0.2
localGroup:insert(popup01)
btnIsActive = “false”

transition.to(popup01,{time = 200, xScale = 1, yScale = 1, alpha = 1})
transition.to(page01bg,{time = 200, alpha = 0.5})
transition.to(pg01img01,{time = 200, alpha = 0.5})
transition.to(pg02img02,{time = 200, alpha = 0.5})

local function removepopup01(event)
transition.to(popup01,{time = 200, xScale = 0.1, yScale = 0.1, alpha = .5})
local function closepopup01()
display.remove(popup01)
btnIsActive = “true”

transition.to(page01bg,{time = 200, alpha = 1})
transition.to(pg01img01,{time = 200, alpha = 1})
transition.to(pg02img02,{time = 200, alpha = 1})
end

timer.performWithDelay(200,closepopup01,1)
end

popup01:addEventListener(“tap”, removepopup01)
end
end
pg01img01:addEventListener(“tap”, spawnpopup01)

local function onComplete()
print(“video playback complete”) – if this doesn’t fire then something is wrong
local function delay()
director:changeScene(“page01”, “fade” )
end

timer.performWithDelay(2, delay)
end

local function playVideo(event)
print(“play video”)
media.playVideo( “video.mp4”, true, onComplete )
end

pg02img02:addEventListener(“touch”, playVideo )

forwardbtn:addEventListener(“touch”,pressforward)

return localGroup
end

–Updating post
Not working on the device built too… Some times its working fine and some times its not… No clue why this is happening… If any one have any idea please let me know…
[import]uid: 83799 topic_id: 26442 reply_id: 107342[/import]

If you want to make up an extremely simple example and zip it up and report a bug (with that file included) here: http://developer.anscamobile.com/content/bug-submission

And put my name in the title or message body of that form, I will investigate it for you to see if it’s a bug on our side or your code.

Please make it as simple as possible, it should contain no more than 3 lua files, main.lua, scene1.lua and scene2.lua

[import]uid: 84637 topic_id: 26442 reply_id: 107523[/import]