Jump to content

How can I stop a music that the player has started ?


drk

Recommended Posts

    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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...