Исходник MP3 Player

aurora_

Участник
Автор темы
11
47
Описание: Музыкальный плеер (можно воспроизводить как и скачанные mp3 файлы, так и mp3 файлы, загруженные на сайтах, например, zaycev.net)
(!) В видео ниже присутствует звук (!)
Lua:
local as = require('moonloader').audiostream_state
local audio = loadAudioStream("Ссылка на ваш mp3 файл") -- Путь к файлу учитывая папку moonloader или прямая веб-ссылка на mp3 файл
local timer,playing,stopped = false
local time = 0
local fontsize20,fontsize12 = nil
-- Вне всего

function imgui.BeforeDrawFrame()
    if fontsize20 == nil then
        fontsize20 = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\arial.ttf', 20.0, nil, imgui.GetIO().Fonts:GetGlyphRangesCyrillic())
    end
    if fontsize12 == nil then
        fontsize12 = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\arial.ttf', 12.0, nil, imgui.GetIO().Fonts:GetGlyphRangesCyrillic())
    end
end
function join_argb(a, r, g, b) -- by FYP
    local argb = b  -- b
    argb = bit.bor(argb, bit.lshift(g, 8))  -- g
    argb = bit.bor(argb, bit.lshift(r, 16)) -- r
    argb = bit.bor(argb, bit.lshift(a, 24)) -- a
    return argb
end
function rainbow(speed, alpha, offset) -- by rraggerr
    local clock = os.clock() + offset
    local r = math.floor(math.sin(clock * speed) * 127 + 128)
    local g = math.floor(math.sin(clock * speed + 2) * 127 + 128)
    local b = math.floor(math.sin(clock * speed + 4) * 127 + 128)
    return r,g,b,alpha
end

function imgui.MusicPlayer(str_id,author,name) -- by aurora
    local p = imgui.GetCursorScreenPos() local draw_list = imgui.GetWindowDrawList() local pos = imgui.GetWindowPos()
    local max = math.floor(getAudioStreamLength(audio)+0.5)
    local n = 120/max
    local col_bg_notactive = imgui.GetColorU32(imgui.GetStyle().Colors[imgui.Col.ModalWindowDarkening])
    local size_author = (imgui.CalcTextSize(author)).x + 4 local size_name = (imgui.CalcTextSize(name)).x + 14
    imgui.PushFont(fontsize20)
        imgui.SetCursorPosY(5)
        imgui.SetCursorPosX(p.x - pos.x)
        imgui.Text(name)
    imgui.PopFont(1)
    imgui.PushFont(fontsize12)
        imgui.SetCursorPosY(23)
        imgui.SetCursorPosX(p.x-pos.x)
        imgui.Text(author)
    imgui.PopFont(1)
    for i = 0, 120 do
        r, g, b, a = rainbow(2, 255, i / -50)
        imgui.GetWindowDrawList():AddRectFilled(imgui.ImVec2(p.x, p.y + 32), imgui.ImVec2(p.x + n*time, p.y + 36), join_argb(a, r, g, b))
    end
    draw_list:AddRectFilled(imgui.ImVec2(p.x + n*time, p.y + 32), imgui.ImVec2(p.x + 120, p.y + 36), col_bg_notactive, 0.0)
    draw_list:AddCircleFilled(imgui.ImVec2(p.x + n*time, p.y + 34), 4,imgui.GetColorU32(imgui.ImVec4(1,1,1,1)))
    local minute = math.floor(max/60)
    local seconds = max%60
    local minute_timer = math.floor(time/60)
    local seconds_timer = time%60 
    if seconds < 10 then
        seconds = '0' .. tostring(seconds)
    end
    if seconds_timer < 10 then
        seconds_timer = '0' .. tostring(seconds_timer)
    end
    imgui.PushFont(fontsize12)
        imgui.SetCursorPos(imgui.ImVec2(p.x+120-21-pos.x,45))
        imgui.Text(minute .. ":" .. seconds)
    imgui.PopFont(1)
    imgui.PushFont(fontsize12)
        imgui.SetCursorPos(imgui.ImVec2(p.x-pos.x,45))
        imgui.Text(minute_timer .. ":" .. seconds_timer)
    imgui.PopFont(1)
    imgui.PushItemWidth(80)
    imgui.SetCursorPos(imgui.ImVec2(7,64))
    if getAudioStreamState(audio) == as.PLAY then
        timer = true
        playing = true
    else
        playing = false
    end
    if imgui.Button("Play",imgui.ImVec2(32,22)) then -- Play music
        time = 0
        setAudioStreamState(audio, as.PLAY)
    end
    imgui.SameLine()
    if imgui.Button("Pause",imgui.ImVec2(41,22)) then -- Pause music
        setAudioStreamState(audio, as.PAUSE)
    end
    imgui.SameLine()
    if imgui.Button("Resume",imgui.ImVec2(52,22)) then -- Resume music
        if stopped then
            setAudioStreamState(audio, as.PLAY)
            stopped = false
        else
            setAudioStreamState(audio, as.RESUME)
        end
    end
    if imgui.Button("Stop",imgui.ImVec2(133,22)) then -- Stop
        timer = false
        stopped = true
        setAudioStreamState(audio, as.STOP)
    end
    if not timer then time = 0 end
    return font_size,time,stopped
end
-- Функции

    while true do wait(0)
        if timer and playing then 
            wait(1000)
            if time < math.floor(getAudioStreamLength(audio)+0.5) then
                time = time + 1
            else
                timer = false
            end
            return time
        end
    end
-- В функцию main
Пример использования:
Lua:
function imgui.OnDrawFrame()
    if not main_window_state.v then
        imgui.Process = false
    end
    if main_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(145,120))
        imgui.SetNextWindowPos(imgui.ImVec2(sw/2, sh/2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5,0.5))
        imgui.Begin(" testing mp3 player", main_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoTitleBar)
        imgui.MusicPlayer('Player',u8'Миа Бойка feat. Егор Шип',u8'Пикачу') -- Имя плеера, Авторы песни, Название песни
        imgui.End()
    end
end
 

штейн

Известный
Проверенный
1,001
687
(!) В видео ниже присутствует звук (!)
всмысле звук? почему ты не предупредил что там тиктокеры в рот ебутся
1598108780813.png

какого хуя)
 

штейн

Известный
Проверенный
1,001
687
  • Вау
  • Влюблен
Реакции: Fott и neverlane

ГОХА | GoxaShow

В АРМИИ С 12.12,ЗАКАЗЫ НЕ ДЕЛАЮ,ТУПЫЕ ВОПРОСЫ-НАХУ
Проверенный
1,860
1,849
бля, мне так лень делать скрипт, сделайте плиз за меня, и можно еще переключения сделать, вперед, назад, а то 1 песню слушать не кайф, а так збс вещь, хоть не буду браузер для музыки запускать
 
  • Нравится
Реакции: G W и lieer