Bug on playing video

 

I have followed a YouTube video to try to play video in my app, however, it kept failed.

The error is like that:
bgtkdg.png

The link of the YouTube video :
https://www.youtube.com/watch?v=nNrBAE39MS0

--Declare the visible width and height of the video \_W = display.viewableContentWidth \_H = display.viewableContentHeight local background = display.newRect(0, 0, \_W, \_H) background:setFillColor(255,255,255) 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, 120, 120); local on = display.newImageRect(onIMG, 120, 120); 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 videoButton = Button.new({ off = "images/playVideo.png", on = "images/playVideoOver.png", x = \_W \* 0.5, y = \_H \* 0.5, callback = function(e) media.playVideo( "rainbow\_loom.mp4" ,true, function(e) print("Video ended"); end) end }) 

Please help. Thanks so much!

       

The error is rather clear.  “on” is nil at line 19 of main.lua.  Your question is why is “on” nil.  That’s most likely because the value of  onIMG is not a valid file name or it’s not a valid image file.

There is more information in the terminal window that might clue you in.  You can always add in additional print statements to see what values you’re getting.   Please read:

http://docs.coronalabs.com/guide/basics/debugging/index.html

Rob

The error is rather clear.  “on” is nil at line 19 of main.lua.  Your question is why is “on” nil.  That’s most likely because the value of  onIMG is not a valid file name or it’s not a valid image file.

There is more information in the terminal window that might clue you in.  You can always add in additional print statements to see what values you’re getting.   Please read:

http://docs.coronalabs.com/guide/basics/debugging/index.html

Rob