Ryan
Ryan

Reputation: 531

How can I skip back a few seconds after pause in VLC Media Player?

I've searched this on the internet, but can't seem to find anything. I know there are hotkeys to skip back a few seconds, and I know there are hotkeys to to pause and play audio/video in VLC Media Player. However, I am using a single foot pedal for transcription and essentially need it to do both. I would like the pedal tap to pause the audio. Then, after tapping again, I would like it to play the audio, but skipping a few seconds back when doing so. Is this possible?

Upvotes: 3

Views: 3287

Answers (3)

Alireza Zebardast
Alireza Zebardast

Reputation: 1

hi there without any extension u can go to preference in the bottom left enable all settings then type hotkeys after that in the hotkeys search back u can easily set shortcut for backward for a few seconds

Upvotes: 0

Tidsfisk
Tidsfisk

Reputation: 11

I expanded on the code provided by Tee by adding a GUI.
I would also like to add a few details of how to get it working.

  1. Create a empty file, name it rollback.lua.
  2. Copy the code provided underneath this list, paste into the file and save.
  3. Move the file to VLCs folder for lua extensions, it should look something like this:
    c:/Program Files/VideoLAN/VLC/lua/extensions
  4. Restart VLC player.
  5. Activate the script by going to (Note! Needs to be done each time you start VLC to use the plugin)
    view > Rollback X Seconds
  6. Select time in seconds you want to rollback and hit save (or save and close).

In order to get your pedal working with this script, simply configure the hotkey in VLC for play/pause toggle.
VLC > Tools > Preferences > Hotkeys > Set "Play/Pause" Global value to be your pedal.
(After you change a Global hotkey, you need to restart VLC in order to get it working...)

The code:

micro_second_unit = 1000000  
TIME_DELTA        = 1     --Default, 
SHOW_OUTPUT       = true
TIME_TO_DISPLAY   = 1.5    --Default


function descriptor()
   return {
      title = "Rollback X Seconds",
      capabilities = {"input-listener", "playing-listener"}
   }
end

function activate()
    dlg = vlc.dialog("Rollback X Seconds")    

    rollback_input         = dlg:add_text_input("1", 2, 1 )    
    rollback_input_label   = dlg:add_label("Seconds to back", 1, 1)

    checkBox = dlg:add_check_box("Show output time ", wasChecked, 3, 3 )

    timeTo_display_box        = dlg:add_text_input(1.5, 2 ,3)
    timeTo_display_box_label  = dlg:add_label("Seconds To Display", 1, 3)

    w2 = dlg:add_button("Save settings", change_step, 3, 4, 1, 1)
    w2 = dlg:add_button("Save and close", updateAndClose, 3, 5, 1, 1)

    done = dlg:add_label( "" , 3, 6)

end
function close()
end
function deactivate()
   vlc.deactivate()
end

function input_changed()
end

function playing_changed()    

    if vlc.playlist.status()=="paused" then

        local timePassed = tonumber(vlc.var.get(vlc.object.input(), "time"))
        local newTime = timePassed - seconds_to_microsecond(TIME_DELTA)

        local newTime_inSeconds     = (newTime/1000000)
        local newTime_inMinutes     = (newTime_inSeconds/60)
        local newTime_inSeconds_restOfMin  = math.fmod(newTime_inSeconds,60)
        local newTime_str           = math.floor(newTime_inMinutes) .. "min " .. round(newTime_inSeconds_restOfMin,1) .."sec"        

        local timePassed_inSeconds  = (timePassed/1000000)
        local timePassed_inMinutes  = (timePassed_inSeconds/60)
        local timePassed_inSeconds_restOfMin  = math.fmod(timePassed_inSeconds,60)

        local timePassed_str  = math.floor(timePassed_inMinutes) .. "min " .. round(timePassed_inSeconds_restOfMin,1) .."sec"


        if SHOW_OUTPUT == true then
            vlc.osd.message("Seconds to Back:" .. TIME_DELTA .. "sec", vlc.osd.channel_register(), "top-right", seconds_to_microsecond(TIME_TO_DISPLAY))  

           vlc.osd.message("New time:" .. newTime_str, vlc.osd.channel_register(), "top-left", seconds_to_microsecond(TIME_TO_DISPLAY))   

           vlc.osd.message("Old time:" .. timePassed_str, vlc.osd.channel_register(), "bottom-left", seconds_to_microsecond(TIME_TO_DISPLAY))   
        end


        vlc.var.set(vlc.object.input(), "time", newTime)
    end
end
function updateAndClose()
   change_step()
   dlg:delete()
end

function change_step()
    done:set_text("Saved")

   TIME_DELTA = tonumber(rollback_input:get_text())

   SHOW_OUTPUT = checkBox:get_checked()

   if SHOW_OUTPUT == true then 
      TIME_TO_DISPLAY = tonumber(timeTo_display_box:get_text())
   end 

end

function round(num, numDecimalPlaces)
  local mult = 10^(numDecimalPlaces or 0)
  return math.floor(num * mult + 0.5) / mult
end

function microsecond_to_seconds(timeToConvert)  

  return timeToConvert / micro_second_unit;
end

function seconds_to_microsecond(timeToConvert)

  return timeToConvert * micro_second_unit;
end

This will work just like Tee's script, the video will jump back each time it's paused.
Only difference is that you can set the amount of time to jump back each time you start the script.
The amount is given in seconds, however you can use decimals for more control...
There's also a checkbox you can tick if you want to display information about the jump.

I also want to thank Tee for his answer!
This is the first lua code I've written (or rather, modified) and it's a bit messy, but it works and I have used it every day since so I thought I might as well share it.

Upvotes: 1

Tee
Tee

Reputation: 414

Save this code as rollback.lua and place it in Program Files\VideoLAN\VLC\lua\extensions folder. Then activate it through View > Rollback X Seconds.

function descriptor()
   return {
      title = "Rollback X Seconds",
      capabilities = {"input-listener", "playing-listener"}
   }
end

function activate()
end
function close()
end
function deactivate()
end

function input_changed()
end

function playing_changed()
    local TIME_DELTA = -3

    if vlc.playlist.status()=="paused" then

        local timePassed = vlc.var.get(vlc.object.input(), "time")
        local newTime = timePassed + TIME_DELTA

        vlc.osd.message(TIME_DELTA, vlc.osd.channel_register(), "top-left", 1400000)        
        vlc.var.set(vlc.object.input(), "time", newTime)
    end
end

Change the variable TIME_DELTA to whatever time change you want on pause

Upvotes: 1

Related Questions