The following code doesn’t work. It finishes the network request, then waits the 1 second for the perform with delay and then crashes when it tries to play the video. I’m guessing it can’t find the file I’m telling it to play even though I’ve given it plenty of time to finish the download and write it to disk.
It crashes only on my Android build. (Did not try iOS, doesn’t crash on simulator).
This is the line from the android debug log:
01-31 21:29:50.503: I/Choreographer(697): Skipped 152 frames! The application may be doing too much work on its main thread.
local function videoListener( event ) if event.phase =="ended" then native.showAlert( "Error!", event.phase, { "OK" } ) end end webView = native.newVideo(display.contentCenterX,titleBar.y+16,display.actualContentWidth,display.actualContentHeight)--[,listener] ) progressView = widget.newProgressView { x = myData.halfW, y = myData.halfH, width = 300, isAnimated = true } local function playVideo(event) webView:load(tostring(vidID) .. ".mp4", system.DocumentsDirectory) webView.y = webView.y+(webView.height/2) widgetGroup:insert( webView ) webView:addEventListener( "video", videoListener ) webView:play() end local function networkListener( event ) if ( event.isError ) then print( "Network error!") end if (event.phase =="progress") then progressView.isVisible = true local percentageDone = event.bytesTransferred / event.bytesEstimated progressView:setProgress(percentageDone) print(percentageDone) elseif (event.phase =="ended") then progressView.isVisible = false timer.performWithDelay( 1000, playVideo) end end local params = {} params.progress = "download" params.response = {filename=vidID .. ".mp4",baseDirectory=system.DocumentsDirectory} local path = system.pathForFile( vidID .. ".mp4", system.DocumentsDirectory ) local fhd = io.open( path ) -- Determine if file exists if fhd then progressView.isVisible = false timer.performWithDelay( 1000, playVideo ) else requestID = network.request( event.params.link, "GET", networkListener,params ) end
If there’s no way to make this work, then is there a way to access the network methods of native.newVideo? All I’m trying to do is display a progress bar of the download.