native.newVideo()

Type Function
Library native.*
Return value Video
Revision 2017.3060
Keywords video, video view, video overlay
See also media.playVideo()
video

Overview

Returns a video object that can be moved and rotated. This API supports local videos (in one of the system directories) or from a remote location (server).

Gotchas

Syntax

native.newVideo( centerX, centerY, width, height )
centerX, centerY (required)

Numbers. The x and y coordinates that correspond to the center of the video object.

width, height (required)

Numbers. The width and height of the video object.

Properties / Methods

See the Video documentation for a list of methods and properties.

Events

See the video event documentation for properties related to various Video object events.

Examples

Local Video
local video = native.newVideo( display.contentCenterX, display.contentCenterY, 320, 480 )
 
local function videoListener( event )
    print( "Event phase: " .. event.phase )
 
    if event.errorCode then
        native.showAlert( "Error!", event.errorMessage, { "OK" } )
    end
end
 
-- Load a video and jump to 0:30
video:load( "myVideo.m4v", system.DocumentsDirectory )
video:seek( 30 )

-- Add video event listener 
video:addEventListener( "video", videoListener )

-- Play video
video:play()

-- Stop the video and remove
video:pause()
video:removeSelf()
video = nil
Remote Video
local video = native.newVideo( display.contentCenterX, display.contentCenterY, 640, 360 )
 
local function videoListener( event )
    print( "Event phase: " .. event.phase )
 
    if event.errorCode then
        native.showAlert( "Error!", event.errorMessage, { "OK" } )
    end
end
 
-- Load a remote video
video:load( "http://www.coronalabs.com/video/bbb/BigBuckBunny_640x360.m4v", media.RemoteSource )

-- Add video event listener 
video:addEventListener( "video", videoListener )

-- Play video
video:play()