cocos_lua 视频播放

functionTestVideo(fileName, posX, posY, width, height)
    local visibleRect = cc.Director:getInstance():getOpenGLView():getVisibleRect()
    local videoFullPath = cc.FileUtils:getInstance():fullPathForFilename("baby.mp4") or fileName

    local width = width or visibleRect.width/2
    local height = height or visibleRect.height/2
    local x = posX or C_WinSize.width/2
    local y = posY or C_WinSize.height/2

    local Layout = ccui.Layout:create() 
    Layout:setAnchorPoint(0.5, 0.5)
    Layout:setPosition(cc.p(x, y))
    Layout:setContentSize(cc.size(width, height))
    self:addChild(Layout)

    -- local img = ccui.ImageView:create("Lobby/res/img/img_avata.png")
    -- img:setContentSize(cc.size(width, height))
    -- img:setPosition(cc.p(width/2, height/2))
    -- Layout:addChild(img)

    local videoPlayer = ccexp.VideoPlayer:create()
    local function onVideoEventCallback(sener, eventType)
        if eventType == ccexp.VideoPlayerEvent.PLAYING then
        elseif eventType == ccexp.VideoPlayerEvent.PAUSED then
        elseif eventType == ccexp.VideoPlayerEvent.STOPPED then
        elseif eventType == ccexp.VideoPlayerEvent.COMPLETED then
            videoPlayer:stop()
            videoPlayer:runAction(cc.Sequence:create(cc.RemoveSelf:create()))
        end
    end

    videoPlayer:setContentSize(cc.size(width,height))
    videoPlayer:setAnchorPoint(cc.p(0.5, 0.5))
    videoPlayer:setPosition(cc.p(width/2, height/2))
    videoPlayer:addEventListener(onVideoEventCallback)
    videoPlayer:setFullScreenEnabled(false)
    videoPlayer:setFileName(videoFullPath)
    videoPlayer:play()
    Layout:addChild(videoPlayer)
end

 

转载于:https://www.cnblogs.com/ebchange/p/10729256.html

你可能感兴趣的:(cocos_lua 视频播放)