Skip to content

Commit 69d13bd

Browse files
committed
docs(video): add video API documentation and type definitions
- Add video texture detection function `IsVideoTexture` to ResourceManager - Add comprehensive video loading and playback API documentation including `LoadVideo`, `VideoSeek`, `VideoSetLooping`, `VideoSetLoopRange`, `VideoUpdate`, `VideoGetInfo`, `VideoGetVideoStreams`, `VideoGetAudioStreams`, and `VideoReopen` - Create new Video.lua type definition file with complete Video class API including static methods, properties, and instance methods - Export all video-related functions to main lstg module for public API access - Remove outdated video example files (video_example.lua and video_example_modern.lua) - Include bilingual documentation (English and Chinese) with usage examples and parameter descriptions
1 parent 13c4ca2 commit 69d13bd

5 files changed

Lines changed: 411 additions & 69 deletions

File tree

LuaSTG/doc/luastg/legacy/ResourceManager.lua

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ end
107107
function M.IsRenderTarget(name)
108108
end
109109

110+
--- [LuaSTG Sub 新增]
111+
--- 判断纹理是否为视频纹理
112+
--- [LuaSTG Sub Add]
113+
--- Check if a texture is a video texture
114+
---@param name string 纹理名称 / Texture name
115+
---@return boolean is_video 是否为视频纹理 / Whether it is a video texture
116+
function M.IsVideoTexture(name)
117+
end
118+
110119
--- 返回纹理或渲染目标的宽度和高度
111120
---@param texname string
112121
---@return number, number
@@ -404,6 +413,133 @@ end
404413
function M.LoadModel(modname, gltfpath)
405414
end
406415

416+
--------------------------------------------------------------------------------
417+
--- 视频
418+
--- Video
419+
420+
--- [LuaSTG Sub 新增]
421+
--- 从文件加载视频纹理
422+
--- 支持常见的视频格式(如 mp4, avi, mkv 等)
423+
--- 加载后的视频可以像普通纹理一样使用,通过 LoadImage 创建精灵
424+
--- [LuaSTG Sub Add]
425+
--- Load video texture from file
426+
--- Supports common video formats (such as mp4, avi, mkv, etc.)
427+
--- The loaded video can be used like a normal texture, create sprite via LoadImage
428+
---
429+
---# 示例 / Example
430+
---```lua
431+
---lstg.LoadVideo('video1', 'test_video.mp4')
432+
---lstg.LoadVideo('video2', 'test_video.mp4', {
433+
--- video_stream = 0,
434+
--- width = 1280,
435+
--- height = 720,
436+
--- looping = true,
437+
--- loop_end = 10.0,
438+
--- loop_duration = 5.0
439+
---})
440+
---lstg.LoadImage('video_sprite', 'video1', 0, 0, 640, 480)
441+
---```
442+
---@param videoname string 视频资源名称 / Video resource name
443+
---@param filepath string 视频文件路径 / Video file path
444+
---@param options? lstg.VideoOpenOptions 视频打开选项 / Video open options
445+
function M.LoadVideo(videoname, filepath, options)
446+
end
447+
448+
--- [LuaSTG Sub 新增]
449+
--- 跳转到视频的指定时间
450+
--- [LuaSTG Sub Add]
451+
--- Seek video to specified time
452+
---@param videoname string 视频资源名称 / Video resource name
453+
---@param time number 目标时间(秒)/ Target time in seconds
454+
---@return boolean success 是否成功 / Success status
455+
function M.VideoSeek(videoname, time)
456+
end
457+
458+
--- [LuaSTG Sub 新增]
459+
--- 设置视频是否循环播放
460+
--- [LuaSTG Sub Add]
461+
--- Set whether the video loops
462+
---@param videoname string 视频资源名称 / Video resource name
463+
---@param loop boolean 是否循环 / Whether to loop
464+
function M.VideoSetLooping(videoname, loop)
465+
end
466+
467+
--- [LuaSTG Sub 新增]
468+
--- 设置视频循环区间
469+
--- 循环区间为 [loop_end - loop_duration, loop_end)
470+
--- 当播放时间超过 loop_end 时,会跳转到 loop_end - loop_duration
471+
--- [LuaSTG Sub Add]
472+
--- Set video loop range
473+
--- Loop range is [loop_end - loop_duration, loop_end)
474+
--- When playback time exceeds loop_end, it jumps to loop_end - loop_duration
475+
---@param videoname string 视频资源名称 / Video resource name
476+
---@param loop_end number 循环结束时间(秒)/ Loop end time in seconds
477+
---@param loop_duration number 循环时长(秒)/ Loop duration in seconds
478+
function M.VideoSetLoopRange(videoname, loop_end, loop_duration)
479+
end
480+
481+
--- [LuaSTG Sub 新增]
482+
--- 更新视频到指定的绝对时间
483+
--- 通常配合 StopWatch 使用来同步视频播放
484+
--- [LuaSTG Sub Add]
485+
--- Update video to specified absolute time
486+
--- Typically used with StopWatch to synchronize video playback
487+
---
488+
---# 示例 / Example
489+
---```lua
490+
---local video_clock = lstg.StopWatch()
491+
---function RenderFunc()
492+
--- lstg.VideoUpdate('video1', video_clock:GetElapsed())
493+
--- lstg.Render('video_sprite', 100, 100)
494+
---end
495+
---```
496+
---@param videoname string 视频资源名称 / Video resource name
497+
---@param time number 目标时间(秒)/ Target time in seconds
498+
---@return boolean success 是否成功 / Success status
499+
function M.VideoUpdate(videoname, time)
500+
end
501+
502+
--- [LuaSTG Sub 新增]
503+
--- 获取视频信息
504+
--- [LuaSTG Sub Add]
505+
--- Get video information
506+
---@param videoname string 视频资源名称 / Video resource name
507+
---@return lstg.VideoInfo info 视频信息表 / Video information table
508+
function M.VideoGetInfo(videoname)
509+
end
510+
511+
--- [LuaSTG Sub 新增]
512+
--- 获取视频文件中的所有视频流信息
513+
--- 用于多轨视频的流选择
514+
--- [LuaSTG Sub Add]
515+
--- Get all video streams in the video file
516+
--- Used for multi-track video stream selection
517+
---@param videoname string 视频资源名称 / Video resource name
518+
---@return lstg.VideoStreamInfo[] streams 视频流信息数组 / Array of video stream info
519+
function M.VideoGetVideoStreams(videoname)
520+
end
521+
522+
--- [LuaSTG Sub 新增]
523+
--- 获取视频文件中的所有音频流信息
524+
--- [LuaSTG Sub Add]
525+
--- Get all audio streams in the video file
526+
---@param videoname string 视频资源名称 / Video resource name
527+
---@return lstg.AudioStreamInfo[] streams 音频流信息数组 / Array of audio stream info
528+
function M.VideoGetAudioStreams(videoname)
529+
end
530+
531+
--- [LuaSTG Sub 新增]
532+
--- 使用新的选项重新打开视频
533+
--- 可用于切换视频流或修改输出尺寸
534+
--- [LuaSTG Sub Add]
535+
--- Reopen video with new options
536+
--- Can be used to switch video streams or change output size
537+
---@param videoname string 视频资源名称 / Video resource name
538+
---@param options? lstg.VideoOpenOptions 新的打开选项 / New open options
539+
---@return boolean success 是否成功 / Success status
540+
function M.VideoReopen(videoname, options)
541+
end
542+
407543
--------------------------------------------------------------------------------
408544
--- 实验性 API
409545

LuaSTG/doc/luastg/lstg.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,10 @@ M.CheckRes = ResourceManager.CheckRes
190190
M.EnumRes = ResourceManager.EnumRes
191191

192192
M.LoadTexture = ResourceManager.LoadTexture
193+
M.LoadVideo = ResourceManager.LoadVideo
193194
M.CreateRenderTarget = ResourceManager.CreateRenderTarget
194195
M.IsRenderTarget = ResourceManager.IsRenderTarget
196+
M.IsVideoTexture = ResourceManager.IsVideoTexture
195197
M.GetTextureSize = ResourceManager.GetTextureSize
196198
M.SaveTexture = ResourceManager.SaveTexture
197199
M.Snapshot = ResourceManager.Snapshot
@@ -227,6 +229,15 @@ M.LoadFX = ResourceManager.LoadFX
227229

228230
M.LoadModel = ResourceManager.LoadModel
229231

232+
M.VideoSeek = ResourceManager.VideoSeek
233+
M.VideoSetLooping = ResourceManager.VideoSetLooping
234+
M.VideoSetLoopRange = ResourceManager.VideoSetLoopRange
235+
M.VideoUpdate = ResourceManager.VideoUpdate
236+
M.VideoGetInfo = ResourceManager.VideoGetInfo
237+
M.VideoGetVideoStreams = ResourceManager.VideoGetVideoStreams
238+
M.VideoGetAudioStreams = ResourceManager.VideoGetAudioStreams
239+
M.VideoReopen = ResourceManager.VideoReopen
240+
230241
M.ResourceManager = ResourceManager.ResourceManager
231242

232243
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)