Remove video

Hello,

I’m having trouble removing a video from my app. This is the code I use:

----------------------------------------------------------------------------------------- -- -- 3.lua -- ----------------------------------------------------------------------------------------- local storyboard = require( "storyboard" ) local widget = require "widget" local scene = storyboard.newScene() local function returnHome() storyboard.gotoScene( "splash", "crossFade", 1000 ) return true end function scene:createScene( event ) local group = self.view audio.fadeOut( { channel=2, time=5000 } ) -- local backgroundMusic = audio.loadStream( "2.wav" ) -- local backgroundMusicChannel = audio.play( backgroundMusic, { channel=3, loops=0 } ) local background = display.newImage("workscreen.png") background.x = display.contentWidth/2 background.y = display.contentHeight/2 local options = { text = "Tot zover verliep operatie Market volgens plan en eenmaal aan de grond kon de opmars naar de doelen (de bruggen) beginnen. ‘Freddie’s Specials’ een verkenningseenheid met snelle jeeps, moest de verkeersbrug bij verrassing innemen en bezet houden tot dat de parabrigade te voet was gearriveerd. Hun instructies waren: ...get to and hold the bridge at Arnhem. If you should encounter the enemy: put your foot down and blast your way through! Er waren echter meteen problemen: het uitladen van de jeeps ging te traag, hun ondersteunende genietroepen kwamen niet opdagen en de geleverde radio’s deden het niet. ‘Freddie’s Specials’ vertrok dus te laat, met te weinig mensen en materieel, zonder ondersteuning en enige vorm van radiocontact. Maar het ergste moest nog komen. Om tijd te winnen nam men een binnen-door-weg, waar ze zich vastreden op een Duitse verdedigingslinie. Het innemen van de brug bij verrassing was dus in een klap mislukt." , x = 120, y = 385, width = 300, --required for multi-line and alignment height = 600, font = native.systemFont, fontSize = 18, align = "left" --new alignment parameter } local myText = display.newText( options ) myText:setFillColor( 0, 0, 0 ) local myTitle = display.newText( "HET VERRASSINGSEFFECT", 950, 40, native.systemFontBold, 40 ) myTitle:setFillColor( 1, 1, 1 ) local video = native.newVideo( 765, 665, 750, 1152 ) local function videoListener( event ) print( "Event phase: " .. event.phase ) if event.errorCode then native.showAlert( "Error!", event.errorMessage, { "OK" } ) end end video:load( "3.wmv", system.ResourceDirectory ) video:addEventListener( "video", videoListener ) video:play() appicon = widget.newButton{ defaultFile="code\_but.png", onRelease = returnHome } appicon.x = 1125 appicon.y = 713 group:insert ( background ) group:insert ( appicon ) group:insert ( myText ) group:insert ( myTitle ) group:insert ( video ) end function scene:enterScene( event ) local group = self.view end function scene:exitScene( event ) local group = self.view end function scene:destroyScene( event ) local group = self.view if appicon then appicon:removeSelf() appicon = nil end end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene

When I use the provided code from the documentation, the video won’t show up.

video:pause() video:removeSelf() video = nil

Thanks,

Rik

Edit: I’m working on Windows, and developing for android.

I don’t see where you’re calling your remove code.  You made the video local inside if your createScene() function.  You might have a scope issue since only your createScene() function and it’s children know about “video”.

Rob

Hi Rob,

Thanks for your reply. I figured it out. I used a timer. This is the code I wrote:

 local function timeywimey( event ) video:pause() video:removeSelf() video = nil end timer.performWithDelay( 120000, timeywimey )

I don’t see where you’re calling your remove code.  You made the video local inside if your createScene() function.  You might have a scope issue since only your createScene() function and it’s children know about “video”.

Rob

Hi Rob,

Thanks for your reply. I figured it out. I used a timer. This is the code I wrote:

 local function timeywimey( event ) video:pause() video:removeSelf() video = nil end timer.performWithDelay( 120000, timeywimey )