aka Blue Posted July 23, 2017 Share Posted July 23, 2017 Estoy creando un sistema de reproducción de canciones para mi servidor de testeos y me gustaría saber (ya que nunca he jugado a fondo con el sound) cómo hacer que se detecte cuando una canción o sound llega a su fin, para así cambiar una variable global. Gracias de antemano! Link to comment
TRtam Posted July 23, 2017 Share Posted July 23, 2017 (edited) Lo que se me ocurrio ahora seria usar un onClientRender: local sound = playSound("sound.mp3") local soundMaxPosition = math.floor(getSoundLength(sound)) function soundRender() local soundPosition = math.floor(getSoundPosition(sound)) if soundPosition >= soundMaxPosition then outputChatBox("Sound finished!") removeEventHandler("onClientRender", root, soundRender) end end addEventHandler("onClientRender", root, soundRender) Edited July 23, 2017 by TRtam getSoundLength* Link to comment
#Dv^ Posted July 23, 2017 Share Posted July 23, 2017 Podrías usar el evento onClientSoundStopped. Link to comment
aka Blue Posted July 23, 2017 Author Share Posted July 23, 2017 Gracias a ambos. De hecho @TRtam, lo tenía en un onClientRender para mostrar un dx la posición, pasa que hacia el mismo check que me has recomendado y el texto desaparecía. Voy a probarlo y comento. Lo tengo así y cuando la inicio, acaba: local sound = nil local soundMaxPos = nil addCommandHandler( "yt", function( cmd, link ) if link then if sound == nil then sound = playSound("https://www.youtubeinmp3.com/fetch/?video="..link) outputChatBox( "Reproduciendo la cancion", 0, 150, 0 ) soundMaxPos = math.floor( getSoundLength( sound ) ) else if isElement( sound ) then stopSound( sound ) sound = nil else sound = nil soundMaxPos = nil end sound = playSound("https://www.youtubeinmp3.com/fetch/?video="..link) soundMaxPos = math.floor( getSoundLength( sound ) ) end else outputChatBox( "Introduce un link para reproducir", 255, 0, 0 ) if isElement( sound ) then stopSound( sound ) sound = nil else sound = nil soundMaxPos = nil end end end ) addEventHandler( "onClientRender", root, function( ) if sound then if math.floor( getSoundPosition( sound ) ) >= soundMaxPos then outputChatBox( "Canción acabada", 0, 150, 0 ) if isElement( sound ) then stopSound( sound ) end sound = nil end end end ) Link to comment
TRtam Posted July 23, 2017 Share Posted July 23, 2017 Ya que estas haciendo un stream de la canción (reproduciendo la canción por una pagina, creo que es así como funciona) tenes que usar onClientSoundStream local sound = nil local soundMaxPos = nil addCommandHandler( "yt", function( cmd, link ) if link then if sound == nil then playSound("https://www.youtubeinmp3.com/fetch/?video="..link) else if isElement( sound ) then stopSound( sound ) sound = nil else sound = nil soundMaxPos = nil end playSound("https://www.youtubeinmp3.com/fetch/?video="..link) end else outputChatBox( "Introduce un link para reproducir", 255, 0, 0 ) if isElement( sound ) then stopSound( sound ) sound = nil else sound = nil soundMaxPos = nil end end end ) addEventHandler( "onClientRender", root, function( ) if sound then if math.floor( getSoundPosition( sound ) ) >= soundMaxPos then outputChatBox( "Canción acabada", 0, 150, 0 ) if isElement( sound ) then stopSound( sound ) end sound = nil end end end ) addEventHandler("onClientSoundStream", resourceRoot, function(suc, length) if not suc then return end sound = source soundMaxPos = math.floor(length) outputChatBox( "Reproduciendo la cancion", 0, 150, 0) end ) Link to comment
Rose Posted July 23, 2017 Share Posted July 23, 2017 Pues como recomendó @#Dv^ con ese evento lo puedes hacer, yo antes hice uno pero con sonidos propios, igual creo sería lo mismo. Link to comment
alex17" Posted July 24, 2017 Share Posted July 24, 2017 4 hours ago, Rose said: Pues como recomendó @#Dv^ con ese evento lo puedes hacer, yo antes hice uno pero con sonidos propios, igual creo sería lo mismo. exacto tanto lió cuando puedes usar onClientSoundStopped. Link to comment
Simple0x47 Posted July 24, 2017 Share Posted July 24, 2017 OnClientRender y ticks still a better option :v Link to comment
aka Blue Posted July 24, 2017 Author Share Posted July 24, 2017 Perfecto. Al final me funcionó el método que me pusieron @alex17" y @#Dv^, pero gracias! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now