frogstar42
New Member
I wanted a simple script that found a folder on my desktop filled with videos. I wanted it to play each video one after another, and then check to see if new files had been added before it looped and started all over again. We played back and forth for an hour but it could not get past the errors.
[videoplaylist.lua] Error running file: ...ata/obs-plugins/frontend-tools/scripts/videoplaylist.lua:27: Error in obs_scene_find_source (arg 1), expected 'struct obs_scene *|obs_scene_t *' got 'struct obs_source *|obs_source_t *'
I was so optimistic and it was polite, patient and helpful to offer new versions but each failed and told me... go here and find one that exists already. (grin)
-- Load the OBS module
obs = require('obslua')
-- Set up the path to the folder
local folder_path = os.getenv("USERPROFILE") .. "\\Desktop\\obs"
-- Get a list of all the video files in the folder
local function get_file_list()
local file_list = {}
for _, file_name in ipairs(os.ls(folder_path)) do
local file_path = folder_path .. "\\" .. file_name
if string.sub(file_name, -4) == ".mp4" then
table.insert(file_list, file_path)
end
end
return file_list
end
-- Set up the media source to play the videos in the playlist
local media_source = obs.obs_source_create("ffmpeg_source", "Video Playlist", nil, nil)
-- Set the media source to loop
obs.obs_source_set_looping(media_source, true)
-- Add the media source to the scene
local scene = obs.obs_frontend_get_current_scene()
local scene_item = obs.obs_scene_find_source(scene, "Video Playlist")
if scene_item == nil then
obs.obs_scene_add(scene, media_source)
else
obs.obs_sceneitem_set_source(scene_item, media_source)
end
-- Loop through the playlist
local file_list = {}
while true do
if #file_list == 0 then
file_list = get_file_list()
end
if #file_list > 0 then
obs.obs_source_media_stop(media_source)
obs.obs_data_set_string(obs.obs_data_create(), "local_file", file_list[1])
obs.obs_source_update(media_source, obs.obs_data_create())
obs.obs_source_media_play(media_source)
for i = 2, #file_list do
obs.obs_data_set_string(obs.obs_data_create(), "local_file", file_list)
obs.obs_source_media_queue(media_source, obs.obs_data_create())
end
file_list = {}
end
obs.timer_sleep(1000)
end
[videoplaylist.lua] Error running file: ...ata/obs-plugins/frontend-tools/scripts/videoplaylist.lua:27: Error in obs_scene_find_source (arg 1), expected 'struct obs_scene *|obs_scene_t *' got 'struct obs_source *|obs_source_t *'
I was so optimistic and it was polite, patient and helpful to offer new versions but each failed and told me... go here and find one that exists already. (grin)
-- Load the OBS module
obs = require('obslua')
-- Set up the path to the folder
local folder_path = os.getenv("USERPROFILE") .. "\\Desktop\\obs"
-- Get a list of all the video files in the folder
local function get_file_list()
local file_list = {}
for _, file_name in ipairs(os.ls(folder_path)) do
local file_path = folder_path .. "\\" .. file_name
if string.sub(file_name, -4) == ".mp4" then
table.insert(file_list, file_path)
end
end
return file_list
end
-- Set up the media source to play the videos in the playlist
local media_source = obs.obs_source_create("ffmpeg_source", "Video Playlist", nil, nil)
-- Set the media source to loop
obs.obs_source_set_looping(media_source, true)
-- Add the media source to the scene
local scene = obs.obs_frontend_get_current_scene()
local scene_item = obs.obs_scene_find_source(scene, "Video Playlist")
if scene_item == nil then
obs.obs_scene_add(scene, media_source)
else
obs.obs_sceneitem_set_source(scene_item, media_source)
end
-- Loop through the playlist
local file_list = {}
while true do
if #file_list == 0 then
file_list = get_file_list()
end
if #file_list > 0 then
obs.obs_source_media_stop(media_source)
obs.obs_data_set_string(obs.obs_data_create(), "local_file", file_list[1])
obs.obs_source_update(media_source, obs.obs_data_create())
obs.obs_source_media_play(media_source)
for i = 2, #file_list do
obs.obs_data_set_string(obs.obs_data_create(), "local_file", file_list)
obs.obs_source_media_queue(media_source, obs.obs_data_create())
end
file_list = {}
end
obs.timer_sleep(1000)
end