drk Posted January 15, 2012 Share Posted January 15, 2012 I tried several ways to do this but I can't. How can I stop a music started by the player from a table? Link to comment
codeluaeveryday Posted January 15, 2012 Share Posted January 15, 2012 stopSound() Stop the variable! Link to comment
drk Posted January 15, 2012 Author Share Posted January 15, 2012 Dude, you know what is table? local musics = { [ 'Music Name' ] = 'url of the music', [ 'Music Name 2' ] = 'url of the music' } Link to comment
FatalTerror Posted January 15, 2012 Share Posted January 15, 2012 Like that ? stopSound(musics['Music Name']) or for i, song in ipairs(musics)do stopSound(song) end Link to comment
drk Posted January 15, 2012 Author Share Posted January 15, 2012 Now the song don't start Don't appear any erros on console or debugscript Link to comment
50p Posted January 15, 2012 Share Posted January 15, 2012 This is not the way to stop the music. You must stop the element returned from playSound/playSound3D. Eg.: mySound = playSound( musics[ "Music1" ] ) -- to stop it: stopSound( mySound ) Link to comment
drk Posted January 15, 2012 Author Share Posted January 15, 2012 function startSound(url, row) local stopTheMusic = isSoundPaused(tostring(url)) if (stopTheMusic == false) then for i, song in ipairs(musics) do stopSound(song) playSound(url) end elseif (stopTheMusic == true) then playSound(url) end end function setMusic() for name, url in pairs(musics) do if guiGridListGetSelectedItem(music_grid) ~= 1 then local row, column = guiGridListGetSelectedItem(music_grid) startSound(tostring(url), row, column, row) end end end addEventHandler('onClientGUIDoubleClick', music_grid, setMusic) I know that startSound is wrong but before the 'for i, song in ipairs(musics) do' ... it starts the music, but don't stop the music when the player start's other. The table is local musics = { [ 'David Guetta - Where Dem Girls At' ] = 'gfx/music/dg-wdga.mp3', [ 'Coldplay - Paradise' ] = 'gfx/music/cp-pd.mp3', [ 'Coldplay - Viva la Vida' ] = 'gfx/music/cp-vlv.mp3', [ 'Ana Malhoa - Danza Kuduro' ] = 'gfx/music/am-dk.mp3', [ 'No Name - Jamming' ] = 'gfx/music/jm.mp3', [ 'Klaas - Make you Feel' ] = 'gfx/music/ks-myf.mp3', [ 'No Name - Vitality' ] = 'gfx/music/vy.mp3', [ 'Basshunter - All I ever wanted' ] = 'gfx/music/bh-aiew.mp3', [ 'Whiz Khalifa - Black and Yellow' ] = 'gfx/music/wk-bay.mp3', [ 'Skrillex - My name is Skrillex ( Remix )' ] = 'gfx/music/sx-mnis.mp3', [ 'Italobrothers - Stamp on the Ground' ] = 'gfx/music/ib-sotg.mp3', [ 'Madcon - Freaky like Me' ] = 'gfx/music/mc-flm.mp3', [ 'Cut the Music - Greatest Deejay' ] = 'gfx/music/ctm-gd.mp3', [ 'No Name - Time`s Vortex' ] = 'gfx/music/tv.mp3', [ 'Manian - Welcome to the Club' ] = 'gfx/music/wttc.mp3', [ 'Bon Jovi - It`s my Life' ] = 'gfx/music/iml.mp3', [ 'Example - Changed the Way you Kissed Me' ] = 'gfx/music/ctwykm.mp3', [ 'Example - Kickstart ( Bar 9 Remix )' ] = 'gfx/music/e-ksb9rx.mp3', [ 'Ellie Goulding - Lights ( Remix )' ] = 'http://199.167.195.194/Lights.mp3' } Link to comment
50p Posted January 15, 2012 Share Posted January 15, 2012 Why do you use for loop to play all the music? Re-read my previous post again. Link to comment
drk Posted January 15, 2012 Author Share Posted January 15, 2012 LOL It isn't to play all the music. It's a radio, when a player double click the music it start. But when the player changes the music on the GUI I don't know how to stop the music that is playing. understand? Link to comment
50p Posted January 15, 2012 Share Posted January 15, 2012 LOL It isn't to play all the music. It's a radio, when a player double click the music it start. But when the player changes the music on the GUI I don't know how to stop the music that is playing. understand? It seems like all you want is the complete script. You seem to ignore the hints. Oh, your for loop will play 1 song 19 times at the same time (it will be louder 19 times). Use break to stop the loop. You have to stop the sound element returned from playSound, not the string representing sound path. ...Eg.: mySound = playSound( musics[ "Music1" ] ) -- to stop it: stopSound( mySound ) Link to comment
drk Posted January 16, 2012 Author Share Posted January 16, 2012 Thanks 50p Problem solved. Please lock this topic. 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