def _media_to_html(
    media_type: str,
    file_source: Union[str, bytes],
    file_type: Optional[str] = None,
    width: Optional[str] = None,
    height: Optional[str] = None,
    autoplay: Optional[bool] = False,
    loop: Optional[bool] = False,
) -> str:
    """
    Convert a media file to an HTML tag with embedded base64 data.

    Args:
        media_type: Type of media ('video', 'audio', or 'image').
        file_source: The path to the media file or a non-b64 encoded byte string.
        file_type: The type of the video file. If not provided, it will be inferred from the file extension.
        width: Display width in HTML. Defaults to None.
        height: Display height in HTML. Defaults to None.
        autoplay: True to autoplay media. Defaults to False.
        loop: True to loop media. Defaults to False.

    Returns:
        HTML tag with embedded base64 data.

    Raises:
        ValueError: If the width and height are not pixel or percentage.
    """
    if not (_is_valid_dimension(width) or _is_valid_dimension(height)):
        raise ValueError("Width and height must be valid pixel (e.g., '300px') or percentage (e.g., '50%') values.")

    file_data, file_type = _get_file_data(file_source, file_type, media_type)
    media_base64 = base64.b64encode(file_data).decode("utf-8")
    data_url = f"data:{media_type}/{file_type};base64,{media_base64}"

    common_attrs = f"{f' width={width}' if width else ''}{f' height={height}' if height else ''}"
    media_attrs = f"{' autoplay' if autoplay else ''}{' loop' if loop else ''}"

    if media_type == "video":
        return f"<video controls{common_attrs}{media_attrs}><source src='{data_url}' type='video/{file_type}'></video>"
    elif media_type == "audio":
        return f"<audio controls{media_attrs}><source src='{data_url}' type='audio/{file_type}'></audio>"
    elif media_type == "image":
        return f'<img src="{data_url}"{common_attrs}>'
    else:
        raise ValueError(f"Unsupported media type: {media_type}")

    Convert a media file to an HTML tag with embedded base64 data.

    Args:
        media_type: Type of media ('video', 'audio', or 'image').
        file_source: The path to the media file or a non-b64 encoded byte string.
        file_type: The type of the video file. If not provided, it will be inferred from the file extension.
        width: Display width in HTML. Defaults to None.
        height: Display height in HTML. Defaults to None.
        autoplay: True to autoplay media. Defaults to False.
        loop: True to loop media. Defaults to False.

    Returns:
        HTML tag with embedded base64 data.

    Raises:
        ValueError: If the width and height are not pixel or percentage.
    
argilla/src/argilla/markdown/media.py