Hi,
I am playing files from an m3u file. VLC shows the total time of the single mp3s (playlist total).
I there any way to show the remaining time? Or how much was played?
Thanks,
Stephan
Code: Select all
-- Playlist total duration
-- Simple extension that shows the current playlist's total duration
-- Lua scripts are tried in alphabetical order in the user's VLC config directory
-- lua/{playlist,meta,intf}/ subdirectory on Windows and Mac OS X or in the user's
-- local share directory (~/.local/share/vlc/lua/... on linux), then in the global
-- VLC lua/{playlist,meta,intf}/ directory.
-- 2021-01-10: extended to show the remaining time of the whole playlist _and_ the whole playlist time:
-- <remaining time in total playlist> / <total playlist time> e.g.:
-- 01:26:22 / 02:58:01
-- ToDo: auto refresh
-- original code from:
-- https://github.com/bentrevor/vlc-total-playlist-duration-extension
-- Extension description
function descriptor()
return { title = "Playlist total duration" ;
version = "1.2" ;
author = "Ben Trevor" ;
shortdesc = "Displays dialog box with played, remaining and current playlist's total duration";
description = "Displays a dialog box with the played time, the remaining time and the total play time of a playlist. Refresh only on Button press" ;
------------------------------------------------------
capabilities = {"playing-listener", "input-listener"},
-- capabilities = { }
------------------------------------------------------
}
end
-- Activation hook
function activate()
window = vlc.dialog("Playlist: played / remaining / total")
window:add_button("refresh", update_duration, 1, 1, 1, 1)
time_label = window:add_label("", 2, 1, 1, 1)
get_playlist_duration()
window:show()
end
function update_duration()
get_playlist_duration()
end
function get_playlist_duration()
-- playing time of total playlist
local total = 0
-- played time in actual track
local track_played_time = 0
-- played time in total playlist
local act_pl_position = 0
-- remaining time in total playlist
local rem_pl_time = 0
-- gives a float between 0 and 1 for the actual position of the actual track, unfortunately...
-- ...the function: vlc.player.get_position() is not working, neither is vlc.player.get_time()
------------------------------------------------------
local inp = vlc.object.input()
if inp then track_played_time = vlc.var.get(inp, "position") end
-- track_played_time = vlc.var.get(vlc.object.input(), "position")
------------------------------------------------------
-- iterates the whole playlist
for key, value in pairs(vlc.playlist.get("playlist", false).children) do
-- if the actual track is reached in playlist, get the played time in playlist
if value.id == vlc.playlist.current() then
-- duration of actual track * position in actual track (float between 0 and 1) + total (since this track)
act_pl_position = total + track_played_time * value.duration
end
-- if the duration is not available it is -1
if value.duration ~= -1 then
total = total + value.duration
end
end
-- remaining playing time is total - actual playing time position in playlist
rem_pl_time = total - act_pl_position
-- actual playing time in playlist / remaining time in playlist / total time in playlist (hh:mm:ss / hh:mm:ss / hh:mm:ss)
time_label:set_text(seconds_to_time(act_pl_position) .. " / " .. seconds_to_time(rem_pl_time) .. " / " .. seconds_to_time(total))
return total
end
-- convert time to readable format (hh:mm:ss)
function seconds_to_time(seconds)
local hours = math.floor(seconds / 3600)
local minutes = math.floor((seconds % 3600) / 60)
local seconds = math.floor(seconds % 60)
-- leading 0 for 1 to 9
if hours < 10 then
hours = "0" .. hours
end
if minutes < 10 then
minutes = "0" .. minutes
end
if seconds < 10 then
seconds = "0" .. seconds
end
-- returns hh:mm:ss
return hours .. ":" .. minutes .. ":" .. seconds
end
-- Deactivation hook
function deactivate()
end
-- stop the extension when the dialog window is closed
function close()
vlc.deactivate()
end
-- stops debug error messages, which stops vlc from crashing. I'm still not sure why...
------------------------------------------------------
input_changed = update_duration
playing_changed = update_duration
------------------------------------------------------
function meta_changed()
end
Return to “VLC media player for Windows Troubleshooting”
Users browsing this forum: Google [Bot] and 68 guests