Rockbox Ports are now being developed for various digital audio players!
local function create_playlist(startdir, file_search, maxfiles)--In lua you can define a function (locally) within another function--find file function is passed to the get_files() fn-- it allows us to do things with the match (accept or reject) function f_filedir_(name) if name:len() <= 2 and (name == "." or name == "..") then return false --reject end if name:find(file_search) ~= nil then maxfiles = maxfiles -1 if maxfiles < 1 then action_set_quit(true) return true end return true --accept else return false --reject end end local norecurse = false -- don't enter subdirs local f_finddir = nil local f_findfile = f_filedir_ local files = {} local dirs = {} local max_depth = 3 dirs, files = get_files(startdir, norecurse, f_finddir, f_findfile, nil, max_depth, dirs, files) if #files > 0 then -- rb.audio("stop") -- for the pb example rb.playlist("create", scrpath .. "/", "playback.m3u8") end for i = 1, #files do if(i > 1) then rb.playlist("insert_track", "/yourtransition_file.mp3" or "?") -- might need to check if exist first... end rb.playlist("insert_track", string.match(files[i], "[^;]+") or "?") end if #files > 0 then rb.playlist("start", 0, 0, 0) --start playing it end for i=1, #dirs do dirs[i] = nil end -- empty table for i=1, #files do files[i] = nil end -- empty table --action_set_quit(false) -- for the pb exampleend -- create_playlist
function playback_event(id, event_data) rb.splash(0, id) rb.sleep(5 * rb.HZ)endlocal evp = rockev.register("playback", playback_event)
function playback_event(id, event_data) -- if ending track event fired, pause playing for 2 seconds. endlocal evp = rockev.register("playback", playback_event)
require("actions")local evt -- Timer handlefunction playback_event(id, event_data) if id == rb.PLAYBACK_EVENT_CUR_TRACK_READY then rb.splash(0, "Track Ready") elseif id == rb.PLAYBACK_EVENT_TRACK_SKIP then rb.splash(0, "Track Skip") elseif id == rb.PLAYBACK_EVENT_TRACK_BUFFER then rb.splash(0, "Track Buffered") elseif id == rb.PLAYBACK_EVENT_TRACK_CHANGE then rb.splash(0, "Track Change") rb.audio("pause") evt = rockev.register("timer", tmr_function, rb.HZ * 2) elseif id == rb.PLAYBACK_EVENT_START_PLAYBACK then rb.splash(0, "Start Playback") elseif id == rb.PLAYBACK_EVENT_TRACK_FINISH then rb.splash(0, "Track Finished") elseif id == rb.PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE then rb.splash(0, "Next Track Id3 Available") else rb.splash(0, "unknown id " .. id) endendfunction tmr_function(id, data) rockev.unregister(evt) -- remove timer rb.audio("resume") rb.splash(rb.HZ * 2, "Timer Fired") rb.lcd_clear_display() rb.lcd_update() rb.splash(0, "Waiting...")enddo local act = rb.actions local quit = false function action_event(action) local event if action == act.PLA_EXIT or action == act.PLA_CANCEL then quit = true end end function action_set_quit(bQuit) quit = bQuit end function action_quit() return quit endendlocal function main() local TRACK_CHANGE = 16 local TRACK_BUFFER = 2 local eva = rockev.register("action", action_event) --local evp = rockev.register("playback", playback_event) --local evp = rockev.register("playback", playback_event, bit.bor(TRACK_CHANGE, TRACK_BUFFER )) local evp = rockev.register("playback", playback_event, TRACK_CHANGE) rb.lcd_clear_display() rb.lcd_update() rb.splash(0, "Waiting...") while not action_quit() do rb.sleep(rb.HZ / 2) end rb.splash(100, "Goodbye")endmain()
require("actions")require("settings")-- Functions for reading / writing settingslocal var = {offset = 1, size = 2, type = 3, fields = 3}local function get_var_fields(s_var) -- converts member string into table -- var = {offset, size, "type"} s_var = s_var or "" local o, s, t = string.match(s_var, "(0x%x+),%s*(%d+),%s*(.+)") local tvar = {o, s, t} return #tvar == var.fields and tvar or nilendlocal function bytesLE_n(str) str = str or "" local tbyte={str:byte(1, -1)} local bpos, num = 1, 0 for k = 1,#tbyte do -- (k = #t, 1, -1 for BE) num = num + tbyte[k] * bpos bpos = bpos * 256 --1<<8 end return numend--local evt -- Timer handlefunction playback_event(id, event_data) if id == rb.PLAYBACK_EVENT_CUR_TRACK_READY then rb.splash(0, "Track Ready") elseif id == rb.PLAYBACK_EVENT_TRACK_SKIP then rb.splash(0, "Track Skip") elseif id == rb.PLAYBACK_EVENT_TRACK_BUFFER then rb.splash(0, "Track Buffered") elseif id == rb.PLAYBACK_EVENT_TRACK_CHANGE then rb.splash(0, "Track Change") --rb.audio("pause") evt = rockev.register("timer", tmr_function, rb.HZ * 2) elseif id == rb.PLAYBACK_EVENT_START_PLAYBACK then rb.splash(0, "Start Playback") elseif id == rb.PLAYBACK_EVENT_TRACK_FINISH then rb.splash(0, "Track Finished") elseif id == rb.PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE then rb.splash(0, "Next Track Id3 Available") else rb.splash(0, "unknown id " .. id) endendfunction tmr_function(id, data) rockev.unregister(evt) -- remove timer rb.audio("resume") rb.splash(rb.HZ * 2, "Timer Fired") rb.lcd_clear_display() rb.lcd_update() rb.splash(0, "Waiting...")enddo local act = rb.actions local quit = false function action_event(action) local event if action == act.PLA_EXIT or action == act.PLA_CANCEL then quit = true end end function action_set_quit(bQuit) quit = bQuit end function action_quit() return quit endendlocal function main() local pbmode = nil; local tvar = get_var_fields(rb.system.global_settings.single_mode) local voffset, vsize, vtype = tvar[var.offset], tvar[var.size], tvar[var.type] if (tvar ~= nil) then local singlemode = 1 pbmode = bytesLE_n(rb.global_settings(voffset, vsize)) if (pbmode ~= nil and pbmode >= 0) then -- set single mode rb.global_settings(voffset, vsize, singlemode) end end local TRACK_CHANGE = 16 local TRACK_BUFFER = 2 local eva = rockev.register("action", action_event) local evp = rockev.register("playback", playback_event, TRACK_CHANGE) rb.lcd_clear_display() rb.lcd_update() rb.splash(0, "Waiting...") while not action_quit() do rb.sleep(rb.HZ / 2) end --restore pbmode if (pbmode ~= nil and pbmode >= 0) then rb.global_settings(voffset, vsize, pbmode) end rb.splash(100, "Goodbye")endmain()
Page created in 0.157 seconds with 22 queries.