Jump to content

Streaming music in website


JoZeF

Recommended Posts

I need server side

  
-- GUI
ww,wh = 455,91
slw,slh = 390,540
sx,sy = guiGetScreenSize()
 
GUIEditor_Window = {}
GUIEditor_Label = {}
GUIEditor_Grid = {}
GUIEditor_Button = {}
GUIEditor_Scroll = {}
GUIEditor_Edit = {}
 
GUIEditor_Window[1] = guiCreateWindow(sx/2 - ww/2, sy + wh,ww,wh,"Now playing...",false)
guiSetAlpha(GUIEditor_Window[1],0.6)
guiWindowSetMovable(GUIEditor_Window[1],false)
guiWindowSetSizable(GUIEditor_Window[1],false)
GUIEditor_Label[1] = guiCreateLabel(0,27,ww,18,"",false,GUIEditor_Window[1])
guiLabelSetColor(GUIEditor_Label[1],255,140,0)
guiLabelSetHorizontalAlign(GUIEditor_Label[1],"center",false)
 
GUIEditor_Window[2] = guiCreateWindow(sx/2 - slw/2, sy/2 - slh/2,slw,slh,"Music Player",false)
guiSetVisible(GUIEditor_Window[2],false)
guiSetAlpha(GUIEditor_Window[2],0.76)
guiWindowSetSizable(GUIEditor_Window[2],false)
GUIEditor_Grid[1] = guiCreateGridList(0,120,slw,302,false,GUIEditor_Window[2])
guiGridListAddColumn(GUIEditor_Grid[1],"Playlist",2)
guiGridListSetSortingEnabled(GUIEditor_Grid[1],false)
GUIEditor_Button[2] = guiCreateButton(9,432,372,29,"Play a new random song",false,GUIEditor_Window[2])
GUIEditor_Label[2] = guiCreateLabel(0,31,slw,15,"Currently playing:",false,GUIEditor_Window[2])
guiLabelSetHorizontalAlign(GUIEditor_Label[2],"center",false)
guiSetFont(GUIEditor_Label[1],"default-bold-small")
GUIEditor_Label[3] = guiCreateLabel(0,50,slw,19,"[ Press F2 to enable the music player ]",false,GUIEditor_Window[2])
guiLabelSetColor(GUIEditor_Label[2],255,140,0)
guiLabelSetHorizontalAlign(GUIEditor_Label[3],"center",false)
guiSetFont(GUIEditor_Label[3],"default-bold-small")
 
 
GUIEditor_Label[4] = guiCreateLabel(0,485,slw,19,"Volume control",false,GUIEditor_Window[2])
guiLabelSetHorizontalAlign(GUIEditor_Label[4],"center",false)
 
GUIEditor_Scroll[1] = guiCreateScrollBar(0,505,slw,22,true,false,GUIEditor_Window[2])
guiScrollBarSetScrollPosition(GUIEditor_Scroll[1],100)
 
GUIEditor_Edit[1] = guiCreateEdit(128,85,253,27,"",false,GUIEditor_Window[2])
GUIEditor_Label[5] = guiCreateLabel(9,85,109,27,"Search for music:",false,GUIEditor_Window[2])
guiLabelSetVerticalAlign(GUIEditor_Label[5],"center")
guiLabelSetHorizontalAlign(GUIEditor_Label[5],"right",false)
guiSetFont(GUIEditor_Label[5],"default-bold-small")
 
 
 
 
-- Vars
songList = {}
recentlyPlayed = {}
 
songCount = 0
songPlaying = false
songPlayingName = false
nextSongTimer = false
 
vol = false
songPauseLocation = 0
musicVolume = 1
 
pausedExternalSounds = {}
 
playingWindowDrawing = false
mapMusicMute = false
 
dir = "up"
 
 
 
 
-- Refresh song list
function refreshSongGridlist(list,count)
    if list and count then
        songCount = tonumber(count)
        songList = list
        balancer = 1
 
        guiGridListClear(GUIEditor_Grid[1])
        for i,k in ipairs(songList) do
            local row = guiGridListAddRow(GUIEditor_Grid[1])
            guiGridListSetItemText(GUIEditor_Grid[1],row,1,string.gsub(k,".mp3",""):gsub(".MP3",""),false,false)
        end
    else
        if songPlaying then
            for i=0,guiGridListGetRowCount(GUIEditor_Grid[1]) do
                local songName = guiGridListGetItemText(GUIEditor_Grid[1],i,1):gsub(".mp3","")
                if songPlayingName == songName then
                    guiGridListSetItemColor(GUIEditor_Grid[1],i,1,100,255,60)
                else
                    guiGridListSetItemColor(GUIEditor_Grid[1],i,1,255,255,255)
                end
            end
        end
    end
end
addEvent("refreshSongList",true)
addEventHandler("refreshSongList",getRootElement(),refreshSongGridlist)
 
 
 
-- Song selection
addEventHandler("onClientGUIDoubleClick",GUIEditor_Grid[1],
function()
    if vol then
        local selected = guiGridListGetSelectedItem(source)
        if selected < 0 then
            return
        end
        local song = guiGridListGetItemText(source,selected,1)
 
        playRandomSong(song)
 
        guiGridListSetSelectedItem(GUIEditor_Grid[1],0,0)
    else
        outputChatBox("#FF8C00*#FFFFFFMusic player is disabled, please enable it with #ABCDEFF2",255,255,255,true)
    end
end,false)
 
 
addEventHandler("onClientGUIClick",GUIEditor_Button[2],
function()
    if vol then
        playRandomSong()
    else
        outputChatBox("#FF8C00*#FFFFFFMusic player is disabled, please enable it with #ABCDEFF2",255,255,255,true)
    end
end,false)
 
 
 
-- Song search
addEventHandler("onClientGUIChanged",GUIEditor_Edit[1],
function()
    local query = guiGetText(source)
    if query == "" then
        guiGridListClear(GUIEditor_Grid[1])
        for i,k in ipairs(songList) do
            local row = guiGridListAddRow(GUIEditor_Grid[1])
            guiGridListSetItemText(GUIEditor_Grid[1],row,1,string.gsub(k,".mp3",""):gsub(".MP3",""),false,false)
        end
    else
        guiGridListClear(GUIEditor_Grid[1])
        local songsFound = 0
        for i,k in ipairs(songList) do
            if k:lower():find(query:lower()) then
                local row = guiGridListAddRow(GUIEditor_Grid[1])
                guiGridListSetItemText(GUIEditor_Grid[1],row,1,string.gsub(k,".mp3",""):gsub(".MP3",""),false,false)
                songsFound = songsFound + 1
            end
        end
 
        if songsFound == 0 then
            local row = guiGridListAddRow(GUIEditor_Grid[1])
            guiGridListSetItemText(GUIEditor_Grid[1], row, 1,"No songs found", false, false )
            guiGridListSetItemColor(GUIEditor_Grid[1], row, 1,255,80,80)
        else
            refreshSongGridlist()
        end
    end
end,false)
 
 
 
 
-- Play a random next song, or a song chosen by player
function playRandomSong(song)
    if not song then
        -- Get a random song, taking into the account the recently played songs
        if isElement(songPlaying) then
            stopSound(songPlaying)
        end
 
        local song = false
 
        if #recentlyPlayed == 0 then
            song = songList[math.random(1,songCount)]
            table.insert(recentlyPlayed,song)
        else
            local validSongList = {}
            for i,k in ipairs(songList) do
                local matchFound = false
                for x,y in ipairs(recentlyPlayed) do
                    if k == y then
                        matchFound = true
                        break
                    end
                end
                if not matchFound then
                    table.insert(validSongList,k)
                end
            end
 
            song = validSongList[math.random(1,#validSongList)]
            if not song then
                song = songList[math.random(1,songCount)]
                outputDebugString("MUSICPLAYER: No valid song could be found, choosing a random one from the whole list...")
            end
 
            table.insert(recentlyPlayed,song)
 
            if #recentlyPlayed >= songCount then
                recentlyPlayed = {}
            end
        end
 
        if (balancer == 1) then
            songPlaying = playSound("kme-clan.g6.cz/test/"..song:gsub(".mp3","")..".mp3")   
        elseif (balancer == 2) then
            songPlaying = playSound("kme-clan.g6.cz/test/"..song:gsub(".mp3","")..".mp3")
        else
            outputChatBox(tostring(balancer))
        end
        songPlayingName = song:gsub(".mp3","")
        setSoundVolume(songPlaying,musicVolume)
        guiSetText(GUIEditor_Label[1],song:gsub(".mp3",""))
        guiSetText(GUIEditor_Label[3],song:gsub(".mp3",""))
 
        refreshSongGridlist()
 
        if vol and not playingWindowDrawing then
            setTimer(popUp,500,1)
        end
 
    else
        -- Play a specific song
        if isElement(songPlaying) then
            stopSound(songPlaying)
        end
        if (balancer == 1) then
            songPlaying = playSound("kme-clan.g6.cz/test/"..song:gsub(".mp3","")..".mp3")   
        elseif (balancer == 2) then
            songPlaying = playSound("kme-clan.g6.cz/test/"..song:gsub(".mp3","")..".mp3")
        else
            outputChatBox(tostring(balancer))
        end
        songPlayingName = song:gsub(".mp3","")
        setSoundVolume(songPlaying,musicVolume)
        guiSetText(GUIEditor_Label[1],song:gsub(".mp3",""))
        guiSetText(GUIEditor_Label[3],song:gsub(".mp3",""))
 
        outputChatBox("#FF8C00* #FFFFFFNow playing \"#ABCDEF"..song:gsub(".mp3","").."#FFFFFF\"",255,255,255,true)
 
        if not playingWindowDrawing then
            popUp()
        else
           
Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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