Back

CreateVideoView

Hello World
Content:
- Methods

The VideoView can be used to play local video files from the filesystem or video streams from remote sources.

vid = app.CreateVideoView( width, height, options ) → app object: VideoView

Use SetFile to set the video file or video stream address.
player.SetFile( "https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_640_3MG.mp4" );
When the video is ready to play, the OnReady callback function will be called, you can then use Play to start playing the video.

If the video cannot be played, the OnError callback function will be called. Use SetOnReady and SetOnError to set the names of your OnReady and OnError callback functions.

Example - Video Stream

function OnStart()
{
    lay = app.CreateLayout( "Linear", "FillXY,VCenter" );

    app.ShowProgress( "Buffering..." );

    player = app.CreateVideoView( 0.9, 0.4 );
    player.SetOnReady( playerOnReady );
    player.SetOnError( player_OnError );
    lay.AddChild( player );

    player.SetFile( "https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_640_3MG.mp4" );

    app.AddLayout( lay );
}

function playerOnReady()
{
    app.HideProgress();
    app.ShowPopup( "Ready" );
    player.Play();
}

function player_OnError(e)
{
    app.HideProgress();
    app.ShowPopup( "Error" );
}
    Copy     Copy All       Run      

Methods

The following methods are available on the VideoView object:

Focus()
GetAbsHeight() → number: integer
GetAbsWidth() → number: integer
GetDuration() → number: float
GetHeight( options ) → number
GetLeft( options ) → number
GetParent() → app object
GetPosition( options ) → object: { left, top, right, bottom }
GetTop( options ) → number
GetType() → string: “VideoView”
GetVisibility() → string: “Show” or “Hide” or “Gone”
GetWidth( options ) → number
Gone()
Hide()
IsEnabled() → boolean
IsOverlap( obj, depth ) → boolean
IsPlaying() → boolean
IsReady() → boolean
IsVisible() → boolean
Method( name, types, p1, p2, p3, p4 ) → all types
Pause()
Play()
SetScale( x, y )
Show()
Stop()
boolean
app object
number
string
unknown
number: factor
number: fraction (0..1)
number: integer
number: milliseconds
number: percent
number: -180..180
number: -100..100
number: 0..100
number: 0..0.99 or 1..256
string:
  hexadecimal: “#rrggbb”, “#aarrggbb”
  colourName: “red”, “green”, ...
string: comma “,” separated
string: path to file or folder ( “/absolute/...” or “relative/...” )
string: “px”
string: “screen”, “px”
string: “left-right” or “right-left” or “top-bottom” or “bottom-top” or “bl-tr” or “br-tl” or “tl-br” or “tr-bl”
string: “repeat”
string: “Add” or “Multiply” or “clear” or “darken” or “lighten” or “overlay” or “screen” or “xor” or “src_in” or “src_out” or “src_atop” or “src_over” or “dst_in” or “dst_out” or “dst_atop” or “dst_over”
string: “px” or “sp” or “dip” or “mm” or “pt”
string: “px” or “sp” or “dip” or “dp” or “mm” or “pt”
string: “Show” or “Hide” or “Gone”
string: “Linear.None” or “Quadratic.In/Out” or “Cubic.In/Out” or “Quartic.In/Out” or “Quintic.In/Out” or “Sinusoidal.In/Out” or “Exponential.In/Out” or “Circular.In/Out” or “Elastic.In/Out” or “Back.In/Out” or “Bounce.In/Out”
string: path to file or folder ( “/absolute/...” or “relative/...” )
string: url path: “http://url” or “https://url”
object: { x, y, w, w, sw, sh, rot }
list: boolean,char,byte,short,int,long,float,double,String,CharSequence,...
function()
vid.AdjustColor
Adjust the visual color effect of the control by setting the Hue (by angle in degrees in a color circle), the saturation, brightness and contrast of the control.
vid.ClearFocus
Removes the focus of the control so that the user no longer has immediate access to it.
vid.Focus
Set the focus to the control so that the user can interact with it immediately.
vid.GetAbsHeight
Get the absolute height of the control in pixels.
vid.GetAbsWidth
Get the absolute width of the control in pixels.
vid.GetDuration
Retunrs the video duration in seconds.
vid.GetHeight
Get the height of the control as screen height relative float or in pixels with the px option.
vid.GetLeft
Get the distance from the control to the left parent border as width relative float or in pixels with the px option.
vid.GetParent
Returns the parent control object where the object was added to - commonly a layout.
vid.GetPosition
Returns data about the position and size of the control.
If the screen option is given the position on the screen will be returned. Otherwise relative to the parent control.
The px options turns the relative values into pixels.
vid.GetTop
Get the distance from the control to the upper parent border as height relative float or in pixels with the px option.
vid.GetType
Returns the control class name.
vid.GetVisibility
Returns the current visibility state of the control. The Values are:
Show: visible
Hide: invisible but still consuming space
Gone: invisible and not consuming space
vid.GetWidth
Get the width of the control as screen width relative float or in pixels with the px option.
vid.Gone
Hides the control without consuming any more layout space as if it were never there.
vid.Hide
Hide the control but keep the layout space free.
vid.IsEnabled
Returns whether the control is currently useable by the user.
vid.IsOverlap
Returns whether the control overlaps with another by a given distance.
vid.IsPlaying
Returns whether the VideoView is currently playing a video
vid.IsReady
Returns whether the video is ready for playing.
vid.IsVisible
Returns whether the control is currently visible to the user, ignoring overlaying controls.
vid.Method
Allows access to other functions defined on the object in Java via reflection.

Note: This function is a premium feature. Please consider subscribing to Premium to use this feature and support DroidScript in its further development.
vid.Pause
Pauses the video.
vid.Play
Plays the video.
vid.SeekTo
Seek the video to given time in seconds.
vid.SetBackAlpha
Set the transparency of the background by an alpha value between 0 (no transparency) and 0.99 (full transparent) or 1 (no transparency) and 256 (full transparent)
vid.SetBackColor
Changes the background color of the control.
vid.SetBackGradient
Define the background color of the control with a gradient. The default gradient direction is from top to bottom, but you can change it from left to right and the reversed versions of course.
vid.SetBackGradientRadial
Define a radial color gradient for the background of control.
vid.SetBackground
Changes the background to an image which can be repeated using the repeat option.
An image which is often used with that option is '/res/drawable/pattern_carbon' - try it out!
vid.SetColorFilter
Adjust the visual color effect with a color and a given BlendMode. More information about BlendMode can be found in the Android Developer page.
vid.SetEnabled
En/Disable the control physically and visually so that the user can/can not access the control. Events like OnTouch will still be fired.
vid.SetFile
Set the video file path or url
vid.SetMargins
Define a distance to other controls on each side of the control.
vid.SetOnComplete
Define a callback function which is called when the playback has finished playing
vid.SetOnError
Define a callback function which is called when an error occured.
vid.SetOnReady
Define a callback function which is called when the video is ready for playback.
vid.SetOnSubtitle
Define a callback function which is called when the subtitle text changed.
vid.SetPadding
Define distances that elements within the control are to maintain from the control borders.
vid.SetPosition
Defines the position and size for the control if the parent is an absolute layout.
vid.SetScale
Scales the control along with its contents by the factors passed to the function.
vid.SetSize
Change the size of the control in either screen relative values or in pixels if the px option was given.
vid.SetSubtitles
Set a subtitle file where to retreive the video subtitles from.
vid.SetVisibility
Change the visibility of the control to one of the available modes:
Show: visible
Hide: invisible but still consuming space
Gone: invisible and not consuming space
vid.SetVolume
Change the video player volume
vid.Show
Set the visibility of the control to “Show”.
vid.Stop
Stop the video playback.
vid.Tween
Performs an animation on the control.
The target object is for the position, size and rotation that the control has at the end of the animation.

The type specifies the behavior and the speed of the animation. Separated by a dot, you must also specify whether you want to apply this behavior to the beginning (In), end (Out), or to both (InOut) times of the animation.

With the amount of repeats you can control how many times you want to play the animation.

If you have jojo activated, the animation will alternate between forward and backward playback, so that if the repetition value is odd, the control will be at the start position again at the end of the animation.

Finally the callback function will be called after the animation has finished. Well, it's about time!