VideoPlayer - Play videos from local files or URLs in an HVArrangement or Dialog.

VideoPlayer
Play videos from local files or URLs in an HVArrangement or Dialog.

GIF_20250323_223845_957

I'm using the VideoView class.


Playback capacity depends primarily on available memory, device resources, and the complexity of the video (resolution, format, etc.). Longer videos tend to consume more resources, which can lead to issues such as stuttering or freezing if the device isn't optimized to handle such loads.


Formats I have tried and that work:
.mp4 | .mov | .3gp | .3g2 | .mkv | .webm


SetVideoPath

Set the video url or file path from the device.

Supported formats:
.mp4 | .mov | .3gp | .3g2 | .mkv | .webm


AttachToArrangement

Set the Arrangement where you want to play the video.


ShowVideoInDialog

Play the video in a dialog.

It fully expands in width and height proportionally whether it is started in a screen position or rotated.

If the video is playing, it will not pause or restart when you rotate the screen, the video will continue to play.

Everything around the dialogue is darkened to provide better focus on the video.


StartVideo

component_method (62)

If the video is paused, calling StartVideo will resume it from where it was paused.


PauseVideo

component_method (64)


StopVideo

Stop playing video.

component_method (65)

The video will stop and the VideoView will close.
If it's the Dialog, it will also close the dialog.


ResetVideoView

Resets the VideoView for reuse in a new container.

component_method (69)


SeekTo

Seeks to a specific position in the video.

blocks - 2025-03-23T052733.882


FormatHoursMinutesSeconds

Convert milliseconds to a formatted HH:mm:ss.


IsPlaying

Returns true if the video is currently playing, false otherwise.

component_set_get (11)


Duration

Gets the total duration of the video in milliseconds.

component_set_get (8)


CurrentPosition

Gets the current position of the video in milliseconds.

component_set_get (10)


CancelOnTouchOutside

Sets whether the dialog can be dismissed by touching outside of it.


VideoPlay

Triggered when the video starts playing.

component_event (40)


VideoPause

Triggered when the video has been paused.

component_event (43)


VideoStop

Triggered when the video has been stopped.

component_event (42)


VideoCompleted

Triggered when the video playback is completed.

component_event (39)


VideoValueChanged

Triggered continuously while the video is playing, providing the current position.


Update v1.1

  • Fixed an issue that caused the app to crash when playing a video in an arrangement and then opening it in a dialog.

  • Setting the CancelOnTouchOutside property to true prevents the dialog box from closing and now also prevents the back button on the device's navigation bar from being used.
    (To exit the video, you'll need to close the app with the other buttons).


aiaProject v1.1
VideoPlayer.aia (29.1 KB)

Extension v1.1
joejsanz.joedevvideoplayer.aix (15.9 KB)


JDK: 11
Minimum API Level: 21
Updated On: 2025-03-25T07:00:00Z

Built using: FAST-CLI v2.8.0


Thanks.

5 Likes

Very nice.

I get a big nasty runtime error when trying to switch between arrangement and dialog.

I did look at that error, but I overlooked it because I assume only the arrangement or the dialog will be used.
Or do you think both will be used in the same interaction?

The error occurs when playing in the Arrangement and then trying to play in the Dialog, but not from the dialog to the arrangement.

This is because the VideoView is embedded in a FrameLayout in the Arrangement and in the Dialog in a RelativeLayout, and they don't match.

If only one is used there is no problem.

:question:
(targetSdkVersion?)

I figured out that one uses the BackPress navigation button to exit the dialog (if you do not use the cancel on touch outside property).

Please follow the naming conventions also for

isPlaying --> IsPlaying

Taifun

I got stuck there, I just copied and pasted the SDKs.

Yes, I tried using a hideSystemUI() function from a separate extension, but it didn't work. When playing, it shows the bars again. I'll have to create an immersive mode. I'll try that tonight.

I'll fix that tonight.

Update v1.1

But you can't, when in dialog :wink:

Like this:

GIF_20250325_064136_618