Video

TsgcHTMLComponent_Video — 渲染一个响应式 HTML5 视频或音频播放器,外加一个 YouTube 嵌入辅助功能,适用于 Delphi、C++ Builder 和 .NET。

TsgcHTMLComponent_Video

一个 HTML5 媒体播放器,发出 <video><audio> 元素。设置来源和播放选项,然后读取 HTML 属性。

组件类

TsgcHTMLComponent_Video

渲染为

HTML5 <video> / <audio> 媒体

语言

Delphi, C++ Builder, .NET

创建它、设置来源、渲染它

赋值 SrcMediaType,切换 ControlsAutoplayResponsive,然后读取 HTML — 或使用静态的 BuildBuildYouTube 辅助方法。

uses
  sgcHTML_Component_Video;

var
  oVid: TsgcHTMLComponent_Video;
begin
  oVid := TsgcHTMLComponent_Video.Create(nil);
  try
    oVid.Src := '/media/intro.mp4';
    oVid.MediaType := mtVideo;
    oVid.Controls := True;
    oVid.Poster := '/media/intro.jpg';
    oVid.Responsive := True;

    WebModule.Response := oVid.HTML;   // <video> element
  finally
    oVid.Free;
  end;
end;

// Or in a single line with the static helpers:
Result := TsgcHTMLComponent_Video.Build('/media/intro.mp4', mtVideo, True);
Result := TsgcHTMLComponent_Video.BuildYouTube('dQw4w9WgXcQ', '100%', '400');
// includes: sgcHTML_Component_Video.hpp

TsgcHTMLComponent_Video *oVid = new TsgcHTMLComponent_Video(NULL);
try
{
  oVid->Src = "/media/intro.mp4";
  oVid->MediaType = mtVideo;
  oVid->Controls = true;
  oVid->Poster = "/media/intro.jpg";
  oVid->Responsive = true;

  String html = oVid->HTML;   // <video> element
}
__finally
{
  delete oVid;
}

// Or in a single line with the static helpers:
String html = TsgcHTMLComponent_Video::Build("/media/intro.mp4", mtVideo, true);
String yt = TsgcHTMLComponent_Video::BuildYouTube("dQw4w9WgXcQ", "100%", "400");
using esegece.sgcWebSockets;

var video = new TsgcHTMLComponent_Video();
video.Src = "/media/intro.mp4";
video.MediaType = TsgcHTMLMediaType.mtVideo;
video.Controls = true;
video.Poster = "/media/intro.jpg";
video.Responsive = true;

string html = video.HTML;   // <video> element

// Or in a single line with the static helpers:
string oneLine = TsgcHTMLComponent_Video.Build("/media/intro.mp4",
    TsgcHTMLMediaType.mtVideo, true);
string yt = TsgcHTMLComponent_Video.BuildYouTube("dQw4w9WgXcQ", "100%", "400");

关键属性与方法

您最常使用的成员。

来源

Src 设置媒体 URL,MediaTypeTsgcHTMLMediaTypemtVideomtAudio)选择渲染的元素。

播放

ControlsAutoplayLoopMuted 直接映射到 HTML5 媒体属性。

尺寸

WidthHeight 设置播放器尺寸;Responsive 将视频包装在 16:9 响应式比例容器中。

海报

Poster 在视频播放前显示一个占位帧;VideoID 设置 DOM id。

YouTube

BuildYouTube(aVideoID, aWidth, aHeight) 通过单个静态调用返回一个响应式 YouTube iframe 嵌入。

一行构建

Build(aSrc, aMediaType, aControls) 通过单个静态调用返回播放器 HTML;HTML 渲染已配置的实例。

继续探索

所有 sgcHTML 组件浏览 60 多个组件的完整功能矩阵。
下载免费试用版30 天试用版附带 60.HTML 演示项目。
价格Single、Team 和 Site 授权,均含完整源代码。

准备好开始了吗?

下载免费试用版,开始在 Delphi、C++ Builder 和 .NET 中构建 Web 界面。