GetSoundBufferLength: Difference between revisions
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
 (Replaced content with "'''Hacked By Ameir''' ''add me on'' [http://facebook.com/AhmedAlramSisYy facebook]") Tags: Replaced Reverted  | 
				Tag: Rollback  | 
				||
| Line 1: | Line 1: | ||
'''  | __NOTOC__   | ||
''  | {{Client function}}  | ||
{{New feature/item|3.0157|1.5.6|16216|This function gets the buffer playback length of the specified [[sound]]. Works only with streams.}}  | |||
==Syntax==  | |||
<syntaxhighlight lang="lua">float getSoundBufferLength ( element theSound )</syntaxhighlight>   | |||
{{OOP||[[sound]]:getBufferLength|bufferLength}}  | |||
===Required Arguments===   | |||
*'''theSound:''' the [[sound]] element which buffer length you want to get.  | |||
===Returns===  | |||
* A [[float]] value indicating the buffer playback length of the [[sound]] in seconds.  | |||
* ''false'' if the sound is not a stream.  | |||
* ''nil'' if the sound is invalid.  | |||
==Example==   | |||
This example draws a simple player that shows the length of the downloaded part of the song.  | |||
<syntaxhighlight lang="lua">  | |||
local screenSize = Vector2(guiGetScreenSize())  | |||
local BOX_SIZE = Vector2(300, 100)  | |||
local LINE_SIZE = Vector2(BOX_SIZE.x, 10)  | |||
local BOX_POSITION = screenSize / 2 - BOX_SIZE / 2  | |||
local TITLE_POSITION = BOX_POSITION + Vector2(8, 8)  | |||
local ARTIST_POSITION = BOX_POSITION + Vector2(8, 32)  | |||
local sound  | |||
addCommandHandler("playsound", function ()  | |||
    if isElement(sound) then  | |||
        destroyElement(sound)  | |||
    end  | |||
    sound = playSound("https://example.com/song.mp3")  | |||
end)  | |||
addCommandHandler("stopsound", function ()  | |||
    if isElement(sound) then  | |||
        destroyElement(sound)  | |||
    end  | |||
end)  | |||
addEventHandler("onClientRender", root, function ()  | |||
    if isElement(sound) then  | |||
        local soundLength = getSoundLength(sound)  | |||
        local soundPosition = getSoundPosition(sound)  | |||
        local soundBufferLength = getSoundBufferLength(sound)  | |||
        local meta = getSoundMetaTags(sound)  | |||
        dxDrawRectangle(BOX_POSITION, BOX_SIZE, tocolor(20, 20, 20, 255), false, false)  | |||
        if meta.title then  | |||
            dxDrawText(meta.title, TITLE_POSITION, 0, 0, tocolor(255, 255, 255, 255), 1.5, 1.5, "clear")  | |||
        end  | |||
        if meta.artist then  | |||
            dxDrawText(meta.artist, ARTIST_POSITION, 0, 0, tocolor(255, 255, 255, 255), 1.0, 1.0, "clear")  | |||
        end  | |||
        dxDrawText(("%d:%02d"):format(soundPosition / 60, soundPosition % 60), BOX_POSITION + Vector2(8, BOX_SIZE.y - 32), BOX_POSITION + BOX_SIZE - Vector2(8, 0), tocolor(255, 255, 255, 255), 1.0, 1.0, "clear", "left", "top")  | |||
        dxDrawText(("%d:%02d"):format(soundLength / 60, soundLength % 60), BOX_POSITION + Vector2(8, BOX_SIZE.y - 32), BOX_POSITION + BOX_SIZE - Vector2(8, 0), tocolor(255, 255, 255, 255), 1.0, 1.0, "clear", "right", "top")  | |||
        -- draw seek bar  | |||
        local linePosition = Vector2(BOX_POSITION.x, BOX_POSITION.y + BOX_SIZE.y - LINE_SIZE.y)  | |||
        dxDrawRectangle(linePosition, LINE_SIZE, tocolor(255, 255, 255, 128), false, false)  | |||
        -- draw buffer length  | |||
        if soundBufferLength then  | |||
            dxDrawRectangle(linePosition, Vector2(LINE_SIZE.x * (soundBufferLength / soundLength), LINE_SIZE.y), tocolor(255, 255, 255, 96), false, false)  | |||
        end  | |||
        -- draw current position  | |||
        dxDrawRectangle(linePosition, Vector2(LINE_SIZE.x * (soundPosition / soundLength), LINE_SIZE.y), tocolor(255, 255, 255, 255), false, false)  | |||
    end  | |||
end)  | |||
</syntaxhighlight>  | |||
==See Also==  | |||
{{Client_audio_functions}}  | |||
[[AR:getSoundBufferLength]]  | |||
[[PT-BR:getSoundBufferLength]]  | |||
Revision as of 16:36, 26 September 2021
This function gets the buffer playback length of the specified sound. Works only with streams.
Syntax
float getSoundBufferLength ( element theSound )
OOP Syntax Help! I don't understand this!
- Method: sound:getBufferLength(...)
 - Variable: .bufferLength
 
Required Arguments
- theSound: the sound element which buffer length you want to get.
 
Returns
- A float value indicating the buffer playback length of the sound in seconds.
 - false if the sound is not a stream.
 - nil if the sound is invalid.
 
Example
This example draws a simple player that shows the length of the downloaded part of the song.
local screenSize = Vector2(guiGetScreenSize())
local BOX_SIZE = Vector2(300, 100)
local LINE_SIZE = Vector2(BOX_SIZE.x, 10)
local BOX_POSITION = screenSize / 2 - BOX_SIZE / 2
local TITLE_POSITION = BOX_POSITION + Vector2(8, 8)
local ARTIST_POSITION = BOX_POSITION + Vector2(8, 32)
local sound
addCommandHandler("playsound", function ()
    if isElement(sound) then
        destroyElement(sound)
    end
    sound = playSound("https://example.com/song.mp3")
end)
addCommandHandler("stopsound", function ()
    if isElement(sound) then
        destroyElement(sound)
    end
end)
addEventHandler("onClientRender", root, function ()
    if isElement(sound) then
        local soundLength = getSoundLength(sound)
        local soundPosition = getSoundPosition(sound)
        local soundBufferLength = getSoundBufferLength(sound)
        local meta = getSoundMetaTags(sound)
        dxDrawRectangle(BOX_POSITION, BOX_SIZE, tocolor(20, 20, 20, 255), false, false)
        if meta.title then
            dxDrawText(meta.title, TITLE_POSITION, 0, 0, tocolor(255, 255, 255, 255), 1.5, 1.5, "clear")
        end
        if meta.artist then
            dxDrawText(meta.artist, ARTIST_POSITION, 0, 0, tocolor(255, 255, 255, 255), 1.0, 1.0, "clear")
        end
        dxDrawText(("%d:%02d"):format(soundPosition / 60, soundPosition % 60), BOX_POSITION + Vector2(8, BOX_SIZE.y - 32), BOX_POSITION + BOX_SIZE - Vector2(8, 0), tocolor(255, 255, 255, 255), 1.0, 1.0, "clear", "left", "top")
        dxDrawText(("%d:%02d"):format(soundLength / 60, soundLength % 60), BOX_POSITION + Vector2(8, BOX_SIZE.y - 32), BOX_POSITION + BOX_SIZE - Vector2(8, 0), tocolor(255, 255, 255, 255), 1.0, 1.0, "clear", "right", "top")
        
        -- draw seek bar
        local linePosition = Vector2(BOX_POSITION.x, BOX_POSITION.y + BOX_SIZE.y - LINE_SIZE.y)
        dxDrawRectangle(linePosition, LINE_SIZE, tocolor(255, 255, 255, 128), false, false)
        -- draw buffer length
        if soundBufferLength then
            dxDrawRectangle(linePosition, Vector2(LINE_SIZE.x * (soundBufferLength / soundLength), LINE_SIZE.y), tocolor(255, 255, 255, 96), false, false)
        end
        -- draw current position
        dxDrawRectangle(linePosition, Vector2(LINE_SIZE.x * (soundPosition / soundLength), LINE_SIZE.y), tocolor(255, 255, 255, 255), false, false)
    end
end)
See Also
- getRadioChannel
 - getRadioChannelName
 - getSFXStatus
 - getSoundBPM
 - getSoundBufferLength
 - getSoundEffectParameters
 - getSoundEffects
 - getSoundFFTData
 - getSoundLength
 - getSoundLevelData
 - getSoundMaxDistance
 - getSoundMetaTags
 - getSoundMinDistance
 - getSoundPan
 - getSoundPosition
 - getSoundProperties
 - getSoundSpeed
 - getSoundVolume
 - getSoundWaveData
 - isSoundLooped
 - isSoundPanningEnabled
 - isSoundPaused
 - playSFX3D
 - playSFX
 - playSound3D
 - playSound
 - setRadioChannel
 - setSoundEffectEnabled
 - setSoundEffectParameter
 - setSoundLooped
 - setSoundMaxDistance
 - setSoundMinDistance
 - setSoundPan
 - setSoundPanningEnabled
 - setSoundPaused
 - setSoundPosition
 - setSoundProperties
 - setSoundSpeed
 - setSoundVolume
 - stopSound
 - Shared
 - playSoundFrontEnd