Author Topic: delay before playing snap  (Read 1934 times)

calle81

  • Sr. Member
  • ****
  • Posts: 184
    • View Profile
delay before playing snap
« on: January 09, 2017, 07:17:51 AM »
Hi, I'm doing themes with full screen video for the pi and I wonder if its possible to add a delay before the snap is played? Its a bit annoying right now when it starts playing immediately when you stop scrolling the wheel. 0.5-1 second delay would be ideal I think. Any help with a code snippet would be greatly appreciated. Thanks :)

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: delay before playing snap
« Reply #1 on: January 09, 2017, 04:08:49 PM »
Yes, you'll need to hook into transition and tick handler, and store a 'delay_timer' value to check it when it reaches your delay time. You'll need to reset that value in Transition.StartLayout, Transition.ToNewList and Transition.FromOldSelection:

Code: [Select]
local settings = {
   delay_timer = 0,
   play_delay = 3000
}

local artwork = fe.add_artwork("snap", 0, 0, 480, 360)

function on_transition(ttype, var, transition_time) {
    if ( ttype == Transition.StartLayout || ttype == Transition.ToNewList || ttype == Transition.FromOldSelection ) {
        artwork.video_flags = Vid.NoAutoStart
        settings.delay_timer = fe.layout.time
    }
    return false
}

function on_tick(tick_time) {
   if ( !artwork.video_playing && tick_time - settings.delay_timer >= settings.play_delay ) artwork.video_playing = true
}

fe.add_ticks_callback(this, "on_tick")
fe.add_transition_callback(this, "on_transition")

This was a quick test, so you might find some quirks and need to adjust it. I also don't have image snaps so I'm not sure if this would show that first - with just videos, the video will be blank and wait until the delay to start. You might have to modify video_flags to show snaps first, then start the video.

calle81

  • Sr. Member
  • ****
  • Posts: 184
    • View Profile
Re: delay before playing snap
« Reply #2 on: January 10, 2017, 02:21:01 AM »
Cool! I will look at this tonight. Thanks!