Video views in Viktor

Hello,

I’d like to ask if it’s possible to insert a video and play it in Viktor? In case it’s not possible, what could be the alternatives?
Thank you in advance.

Huy

Hi Huy,

You could use a webview with a video element as follows:

import viktor as vkt


class Parametrization(vkt.Parametrization):
    # Video URL input
    video_url = vkt.TextField(
        "Video URL", 
        default="https://www.w3schools.com/html/mov_bbb.mp4",
        description="Enter the URL of your video file (MP4, WebM, OGV formats supported)"
    )


class Controller(vkt.Controller):
    parametrization = Parametrization

    @vkt.WebView("Video Player", duration_guess=1)
    def show_video(self, params, **kwargs):
        """
        Display a simple video player using HTML5 video element.
        """
        
        # Check if video URL is provided
        if not params.video_url:
            return vkt.WebResult(html="<p>Please enter a video URL.</p>")
        
        # Create minimal HTML content with video player
        html_content = f"""
        <video width="100%" height="400" controls>
            <source src="{params.video_url}" type="video/mp4">
            <source src="{params.video_url}" type="video/webm">
            <source src="{params.video_url}" type="video/ogg">
            Your browser does not support the video tag.
        </video>
        """
        
        return vkt.WebResult(html=html_content)