Theora Event.COMPLETE

From GiderosMobile
Revision as of 22:29, 13 November 2026 by MoKaLux (talk | contribs) (Created page with "'''Available since:''' Gideros 2017.10<br/> '''Value:''' complete<br/> '''Defined by:''' Ogg<br/> === Description === This event is dispatched by the channel returned by...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Available since: Gideros 2017.10
Value: complete
Defined by: Ogg

Description

This event is dispatched by the channel returned by Theora:play() when the stream reaches its end. With looping enabled the stream restarts instead of finishing.

Example

	local ok, err = pcall(function()
		local channel = videoSource:play(0, looping)
		videoChannel = channel
		readLength()

		local info
		if theoraCore then
			info = theoraCore.getVideoInfo(channel:getStreamId())
		end

		if info then
			-- Fit the video inside the card, keeping its aspect ratio.
			local maxW, maxH = VIDEO_W - VIDEO_PAD * 2, VIDEO_H - VIDEO_PAD * 2
			local scale = math.min(maxW / info.width, maxH / info.height)
			local w = math.floor(info.width * scale)
			local h = math.floor(info.height * scale)

			videoMesh = channel:getVideo(w, h)
			videoMesh:setPosition(
				math.floor(VIDEO_X + (VIDEO_W - w) / 2),
				math.floor(VIDEO_Y + (VIDEO_H - h) / 2))
			videoMesh:addEventListener(Event.TOUCHES_BEGIN, function()
				togglePlay()
				return true
			end)
			videoLayer:addChild(videoMesh)

			local parts = { string.format("%d x %d", info.width, info.height) }
			if info.fps then
				table.insert(parts, string.format("%d fps", math.floor(info.fps + 0.5)))
			end
			if videoLength > 0 then
				table.insert(parts, string.format("%.1f s", videoLength / 1000))
			end
			metaLabel:setText(table.concat(parts, "   "))
			centerX(metaLabel, 334)

			print("[theora] playing", VIDEO_PATH,
				info.width .. "x" .. info.height,
				"fps=" .. tostring(info.fps),
				"length=" .. tostring(videoLength))
		end

		channel:addEventListener(Event.COMPLETE, function()
			if videoChannel == channel then
				fallbackState = "Finished"
				refreshPlayButton()
				refreshStatus()
			end
		end)
	end)