native.newVideo()

Type Function
Library native.*
Return value Video
Revision Release 2022.3683
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 (streaming).

Gotchas

Syntax

native.newVideo( x, y, width, height )
x (required)

Number. The x coordinate that corresponds to the center of the video object.

y (required)

Number. The y coordinate that corresponds to the center of the video object.

width (required)

Number. Width of the video object.

height (required)

Number. 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( "https://coronalabs.com/video/bbb/BigBuckBunny_640x360.m4v", media.RemoteSource )

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

-- Play video
video:play()