-- Helpers Video ----------------------------------------
local VIDEO_PATH = 'Data/Video/Scenes/'
local VIDEO_PATH_CE = 'Data/ExtraContent/Videos/Scenes/'
local SOUND_PATH = 'Data/Sounds/Scenes/'
local SOUND_PATH_CE = 'Data/ExtraContent/Sounds/Scenes/'

function createVideo(info)

    local videoName			= info.video
    local soundName			= info.sound
    local voiceName         = info.voice
    local isAlpha			= info.isAlpha
    local isLooped			= info.isLooped
    local parent			= info.parent
    local x					= info.x	
    local y					= info.y
    local order				= info.order
    local scale				= info.scale
    local scaleX            = info.scaleX or scale
    local scaleY            = info.scaleY or scale
    local isDestroyOnEnd	= info.isDestroyOnEnd
    local soft              = info.soft
    local isHideOnStop      = info.isHideOnStop

	local level = current_scene:getPlayField()
	local path_video = VIDEO_PATH
	local path_sound = SOUND_PATH
	
	if IsLevelCollectorsEdition(level:getName()) then
        path_video = VIDEO_PATH_CE
        path_sound = SOUND_PATH_CE	
	end
	
	local videoPath = string.match(videoName, '%w+/.+\.%w+') and videoName or path_video .. level:getName() .. '/' .. videoName .. '.webm'
    local soundPath = ( soundName and soundName ~= '' ) and ( string.match(soundName, '%w+/.+\.%w+') and soundName or path_sound .. level:getName() .. '/' .. soundName .. '.ogg' ) or nil
	local voicePath = ( voiceName and voiceName ~= '' ) and ( string.match(voiceName, '%w+/.+\.%w+') and voiceName or path_sound .. level:getName() .. '/' .. voiceName .. '.ogg' ) or nil
	
	local video = CreateVideoEntity(videoPath, isAlpha or false)
    video:setName( ExtractFileName(videoPath) )
    video:setLooped(isLooped or false)
    video:attachTo( parent and ( type(parent) == 'string' and level:getEntityNamed(parent) or parent ) or level:getMainEntity() )
    video:setXY(x or 512, y or 384)
    video:setOrder(order or 0)
    video:setScaleX(scaleX or 1)
    video:setScaleY(scaleY or 1)
    video:setRespondable(false)
    video:setSoftEdgesSize(soft or Vector2f(0, 0))

    if isHideOnStop then
        video.onFinish:add(function() video:hide() end)
    end

    if isDestroyOnEnd then
    	video.onFinish:add(function() video:destroy() end)
    end
    
    if soundPath then
		video:setSoundTrack(soundPath)
	end

    if voicePath then
        local voice = CreateVoiceTrack(voicePath)
        voice:attachTo(video)
        voice:play()
    end

    video:stop()
	return video
end