Prezados,
Venho tentando criar um exibidor de legendas .srt em NCLua, mas estou completamente empacado e acredito que o problema esteja nas minha chamadas ao event.timer(). A primeira legenda vai bem, até que eu inseri um loop repeat-until no código com o objetivo de terminar de ler o arquivo.
Segue o código-fonte. Se alguém puder me ajudar, serei grato.
-- legendas.lua -- Exibidor de legendas em formato SRT -- Inicializacao das variaveis local tempoAcumulado, tempoInicial, duracao, tempoFinal = 0, 0, 0 local dx, dy = canvas:attrSize() local texto = '' canvas:attrFont('vera', 24, 'bold') canvas:attrColor (0,0,0,0) canvas:drawRect ('fill',0,0,dx,dy) function finaliza () event.post { class = 'ncl', type = 'presentation', action = 'stop' } end function handler (evt) texto = 'Isto eh um teste' io.input('Capoeira.srt') if io.read() == nil then finaliza() end repeat --carrega os tempos tempos = io.read() tempoInicial = (string.sub(tempos, 0, 2) * 3600000) + (string.sub(tempos, 4, 5) * 60000) + (string.sub(tempos, 7, 8) * 1000) + string.sub(tempos, 10, 12) tempoFinal = (string.sub(tempos, 18, 19) * 3600000) + (string.sub(tempos, 21, 22) * 60000) + (string.sub(tempos, 24, 25) * 1000) + string.sub(tempos, 27, 29) duracao = tempoFinal - tempoInicial event.timer(tempoInicial-tempoAcumulado, function() texto = io.read() ax,ay = canvas:measureText(texto) canvas:attrColor ('black') canvas:drawText (((dx-ax)/2)+1, 11, texto) canvas:attrColor ('yellow') canvas:drawText ((dx-ax)/2, 10, texto) canvas:flush() tempoAcumulado = tempoInicial+(tempoInicial-TempoAcumulado) event.timer(duracao, function() canvas:attrColor (0,0,0,0) canvas:drawRect ('fill',0,0,dx,dy) canvas:flush() tempoAcumulado = tempoAcumulado+duracao end) end) io.read() until io.read() == nil end event.register(handler)
Autor: Flávio Pontes
33 comentários
<property name="path"/>
<property name="fps"/>
<property name="color"/>
</media>
<link xconnector="conn#onBeginSet">
<bind role="onBegin" component="subtitle"/>
<bind role="set" component="subtitle" interface="path">
<bindParam name="var" value="media/ASharedCulture211_portugues.srt"/>
</bind>
<bind role="set" component="subtitle" interface="fps">
<bindParam name="var" value="10"/>
</bind>
<bind role="set" component="subtitle" interface="color">
<bindParam name="var" value="white"/>
</bind>
</link>
{class='ncl', type='attribution', name='fps', value=?}, ou
{class='ncl', type='attribution', name='color', value=?}, e executa a acao correspondente -- que pode ser, inclusive, atribuir o campo valor a uma variavel homonima no script. Espero que isso ajude.