звук

pchelkin (mearfy)

Известный
Автор темы
900
373
Версия MoonLoader
.026-beta
как сделать воспроизведение и отключение звука/мп3 файла
 

01010110 01100001 0110010

Потрачен
331
35
как сделать воспроизведение и отключение звука/мп3 файла


Mp3. 0.26:
script_name('MP3 Player')
script_version('1')
script_author("Katsuro | #Northn")
script_properties('work-in-pause')

local encoding = require 'encoding'
local imgui = require 'imgui'
local u8 = encoding.UTF8
local activate = imgui.ImBool(false)
local as_action = require('moonloader').audiostream_state
local volume = imgui.ImFloat('50')
local antiafkmode = imgui.ImBool(false)
local selected = 1
local searchBuf = imgui.ImBuffer(256)
encoding.default = 'CP1251'

function apply_custom_style()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    style.WindowRounding = 5.0
    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.84)
    style.ChildWindowRounding = 2.0
    style.FrameRounding = 2.0
    style.ItemSpacing = imgui.ImVec2(5.0, 4.0)
    style.ScrollbarSize = 10.0
    style.ScrollbarRounding = 1
    style.GrabMinSize = 8.0
    style.GrabRounding = 1.0
    -- style.Alpha =
    -- style.WindowPadding =
    -- style.WindowMinSize =
    -- style.FramePadding =
    -- style.ItemInnerSpacing =
    -- style.TouchExtraPadding =
    -- style.IndentSpacing =
    -- style.ColumnsMinSpacing = ?
    -- style.ButtonTextAlign =
    -- style.DisplayWindowPadding =
    -- style.DisplaySafeAreaPadding =
    -- style.AntiAliasedLines =
    -- style.AntiAliasedShapes =
    -- style.CurveTessellationTol =
    colors[clr.Text]                   = ImVec4(1.00, 1.00, 1.00, 1.00)
    colors[clr.TextDisabled]           = ImVec4(0.50, 0.50, 0.50, 1.00)
    colors[clr.WindowBg]               = ImVec4(0.06, 0.06, 0.06, 0.94)
    colors[clr.ChildWindowBg]          = ImVec4(1.00, 1.00, 1.00, 0.00)
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.ComboBg]                = colors[clr.PopupBg]
    colors[clr.Border]                 = ImVec4(0.43, 0.43, 0.50, 0.50)
    colors[clr.BorderShadow]           = ImVec4(0.00, 0.00, 0.00, 0.00)
    colors[clr.FrameBg]                = ImVec4(0.16, 0.29, 0.48, 0.54)
    colors[clr.FrameBgHovered]         = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.FrameBgActive]          = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.TitleBg]                = ImVec4(0.04, 0.04, 0.04, 1.00)
    colors[clr.TitleBgActive]          = ImVec4(0.16, 0.29, 0.48, 1.00)
    colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.MenuBarBg]              = ImVec4(0.14, 0.14, 0.14, 1.00)
    colors[clr.ScrollbarBg]            = ImVec4(0.02, 0.02, 0.02, 0.53)
    colors[clr.ScrollbarGrab]          = ImVec4(0.31, 0.31, 0.31, 1.00)
    colors[clr.ScrollbarGrabHovered]   = ImVec4(0.41, 0.41, 0.41, 1.00)
    colors[clr.ScrollbarGrabActive]    = ImVec4(0.51, 0.51, 0.51, 1.00)
    colors[clr.CheckMark]              = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.SliderGrab]             = ImVec4(0.24, 0.52, 0.88, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.Button]                 = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.ButtonHovered]          = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ButtonActive]           = ImVec4(0.06, 0.53, 0.98, 1.00)
    colors[clr.Header]                 = ImVec4(0.26, 0.59, 0.98, 0.31)
    colors[clr.HeaderHovered]          = ImVec4(0.26, 0.59, 0.98, 0.80)
    colors[clr.HeaderActive]           = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.Separator]              = colors[clr.Border]
    colors[clr.SeparatorHovered]       = ImVec4(0.26, 0.59, 0.98, 0.78)
    colors[clr.SeparatorActive]        = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ResizeGrip]             = ImVec4(0.26, 0.59, 0.98, 0.25)
    colors[clr.ResizeGripHovered]      = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.ResizeGripActive]       = ImVec4(0.26, 0.59, 0.98, 0.95)
    colors[clr.CloseButton]            = ImVec4(0.41, 0.41, 0.41, 0.50)
    colors[clr.CloseButtonHovered]     = ImVec4(0.98, 0.39, 0.36, 1.00)
    colors[clr.CloseButtonActive]      = ImVec4(0.98, 0.39, 0.36, 1.00)
    colors[clr.PlotLines]              = ImVec4(0.61, 0.61, 0.61, 1.00)
    colors[clr.PlotLinesHovered]       = ImVec4(1.00, 0.43, 0.35, 1.00)
    colors[clr.PlotHistogram]          = ImVec4(0.90, 0.70, 0.00, 1.00)
    colors[clr.PlotHistogramHovered]   = ImVec4(1.00, 0.60, 0.00, 1.00)
    colors[clr.TextSelectedBg]         = ImVec4(0.26, 0.59, 0.98, 0.35)
    colors[clr.ModalWindowDarkening]   = ImVec4(0.80, 0.80, 0.80, 0.35)
end

apply_custom_style()

function main()
    while not isSampAvailable() do wait(50) end
    if not doesDirectoryExist('moonloader/MP3 Player') then createDirectory('moonloader/MP3 Player') end
    sampRegisterChatCommand('mp3pl', function() activate.v = not activate.v end)
    while true do wait(0)
        imgui.Process = activate.v
    end
end

function imgui.OnDrawFrame()
    if activate.v then
        local musiclist = getMusicList()
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(810, 510), imgui.Cond.FirstUseEver)
        imgui.Begin(u8'MP3 Player | ������� ���� | �����������: Katsuro | #Northn', activate)
        local btn_size = imgui.ImVec2(-0.1, 0)
        imgui.Text(' ')
        imgui.SameLine(nil, 270)
        if imgui.Button(u8'������ �������') then selected2 = 1 end
        imgui.SameLine(nil, 3)
        if imgui.Button(u8'������ ������') then selected2 = 2 end
        imgui.Separator()
        if selected2 == 1 then
            imgui.BeginChild('##left', imgui.ImVec2(350, 0), true)
            for num, name in pairs(musiclist) do
                local name = name:gsub('.mp3', '')
                if imgui.Selectable(u8(name), false) then selected = num end
            end
            imgui.EndChild()
            imgui.SameLine()
            imgui.BeginChild('##right', imgui.ImVec2(0, 0), true)
            imgui.SameLine()
            for num, name in pairs(musiclist) do
                if num == selected then
                    local namech = name:gsub('.mp3', '')
                    imgui.Text(u8(namech))
                    imgui.Spacing()
                    imgui.Separator()
                    imgui.Spacing()
                    imgui.SameLine(150)
                    if imgui.Button(u8'�������� ��� �����') then
                        if playsound ~= nil then setAudioStreamState(playsound, as_action.STOP) playsound = nil end
                        playsound = loadAudioStream('moonloader/MP3 Player/'..name)
                        setAudioStreamState(playsound, as_action.PLAY)
                        setAudioStreamVolume(playsound, math.floor(volume.v))
                    end
                    imgui.Spacing()
                    imgui.Separator()
                    imgui.Spacing()
                    imgui.SameLine(125)
                    if imgui.Button(u8'�������������') then if playsound ~= nil then setAudioStreamState(playsound, as_action.PAUSE) end end
                    imgui.SameLine(nil, 3)
                    if imgui.Button(u8'����������') then if playsound ~= nil then setAudioStreamState(playsound, as_action.RESUME) end end
                    imgui.Text(' ')
                    imgui.SameLine(50)
                    imgui.SliderFloat(u8'���������', volume, 0, 100)
                    if playsound ~= nil then setAudioStreamVolume(playsound, math.floor(volume.v)) end
                end
            end
            imgui.EndChild()
        else
            for i = 0, 5 do imgui.Text(' ') end
            imgui.Spacing()
            imgui.SameLine(200)
            imgui.Text(u8'� ���� ���� ������� ������ ������-������ �� ����� / ������������.')
            imgui.Spacing()
            imgui.SameLine(142)
            imgui.InputText("##search", searchBuf, imgui.InputTextFlags.EnterReturnsTrue + imgui.InputTextFlags.CharsNoBlank)
            imgui.Spacing()
            imgui.SameLine(337)
            if imgui.Button(u8'��������� �� ������') then
                if searchBuf.v ~= '' and string.lower(searchBuf.v):find('http') then
                    if onlinesong ~= nil then setAudioStreamState(onlinesong, as_action.STOP) end
                    onlinesong = loadAudioStream(searchBuf.v)
                    setAudioStreamState(onlinesong, as_action.PLAY)
                    setAudioStreamVolume(onlinesong, math.floor(volume.v))
                end
            end
            imgui.Spacing()
            imgui.SameLine(311)
            if imgui.Button(u8'�������������') then if onlinesong ~= nil then setAudioStreamState(onlinesong, as_action.PAUSE) end end
            imgui.SameLine(nil, 3)
            if imgui.Button(u8'����������') then if onlinesong ~= nil then setAudioStreamState(onlinesong, as_action.RESUME) end end
            imgui.Spacing()
            imgui.SameLine(142)
            imgui.SliderFloat(u8'���������', volume, 0, 100)
            if onlinesong ~= nil then setAudioStreamVolume(onlinesong, volume.v / 100) end
        end
        imgui.End()
    end
end
        
function getMusicList()
    local files = {}
    local handleFile, nameFile = findFirstFile('moonloader/MP3 Player/*.mp3')
    while nameFile do
        if handleFile then
            if not nameFile then
                findClose(handleFile)
            else
                files[#files+1] = nameFile
                nameFile = findNextFile(handleFile)
            end
        end
    end
    return files
end
 
  • Эм
  • Вау
Реакции: pchelkin (mearfy) и qdIbp

qdIbp

Автор темы
Проверенный
1,447
1,196
 
  • Нравится
Реакции: pchelkin (mearfy)