Skip to content

Commit

Permalink
Added a Video sample.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinnegatamante committed Apr 6, 2021
1 parent d0bdfda commit 906d5de
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 2 deletions.
75 changes: 75 additions & 0 deletions samples/Video/index.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
local white = Color.new(255,255,255)

-- Init video device
Video.init()

-- Loading and starting our video file
Video.open("ux0:/data/lpp-vita/samples/Video/video.mp4")
Video.openSubs("ux0:/data/lpp-vita/samples/Video/video.vtt")

local modes = {
NORMAL_MODE,
FAST_FORWARD_2X_MODE,
FAST_FORWARD_4X_MODE,
FAST_FORWARD_8X_MODE,
FAST_FORWARD_16X_MODE,
FAST_FORWARD_32X_MODE
}

local mode_idx = 1
local oldpad = 0

-- Main loop
while true do

-- Blend instructions
Graphics.initBlend()
Screen.clear()
frame = Video.getOutput()
if frame ~= 0 then
w = Graphics.getImageWidth(frame)
h = Graphics.getImageHeight(frame)
Graphics.setImageFilters(frame, FILTER_LINEAR, FILTER_LINEAR)
Graphics.drawScaleImage(0, 0, frame, 960 / w, 544 / h)
end
Graphics.debugPrint(20, 20, "Time (ms): " .. Video.getTime(), Color.new(255, 255, 255))
Graphics.debugPrint(20, 40, "Speed: x" .. modes[mode_idx] / 100, Color.new(255, 255, 255))
Graphics.debugPrint(20, 500, Video.getSubs(), Color.new(255, 255, 255))
Graphics.termBlend()
Screen.waitVblankStart()
Screen.flip()

-- Check for input
local pad = Controls.read()
if Controls.check(pad, SCE_CTRL_CIRCLE) and Video.isPlaying() then
Video.pause()
elseif Controls.check(pad, SCE_CTRL_SQUARE) and not Video.isPlaying() then
Video.resume()
elseif Controls.check(pad, SCE_CTRL_TRIANGLE) then
Video.close()
break
elseif Controls.check(pad, SCE_CTRL_LTRIGGER) and not Controls.check(oldpad, SCE_CTRL_LTRIGGER) then
mode_idx = mode_idx - 1
if mode_idx < 1 then
mode_idx = 1
end
Video.setPlayMode(modes[mode_idx])
elseif Controls.check(pad, SCE_CTRL_RTRIGGER) and not Controls.check(oldpad, SCE_CTRL_RTRIGGER) then
mode_idx = mode_idx + 1
if mode_idx > #modes then
mode_idx = #modes
end
Video.setPlayMode(modes[mode_idx])
elseif Controls.check(pad, SCE_CTRL_LEFT) and not Controls.check(oldpad, SCE_CTRL_LEFT) then
local cur_time = Video.getTime()
jump_time = cur_time - 10000
if jump_time < 0 then
jump_time = 0
end
Video.jumpToTime(jump_time)
elseif Controls.check(pad, SCE_CTRL_RIGHT) and not Controls.check(oldpad, SCE_CTRL_RIGHT) then
Video.jumpToTime(Video.getTime() + 10000)
end

oldpad = pad
end
Binary file added samples/Video/video.mp4
Binary file not shown.
40 changes: 40 additions & 0 deletions samples/Video/video.vtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
WEBVTT
00:02.170 --> 00:04.136
Emo, close your eyes

00:04.136 --> 00:05.597
Why?
NOW!

00:05.597 --> 00:07.405
Ok

00:07.405 --> 00:08.803
Good

00:08.803 --> 00:11.541
What do you see at your left side Emo?

00:11.541 --> 00:13.287
Well?

00:13.287 --> 00:16.110
Er nothing?
Really?

00:16.110 --> 00:18.514
No, nothing at all!

00:18.514 --> 00:22.669
Really? and at your right? What do you see at your right side Emo?

00:22.669 --> 00:26.111
Umm, the same Proog

00:26.111 --> 00:28.646
Exactly the same! Nothing!

00:28.646 --> 00:30.794
Great

4 changes: 2 additions & 2 deletions source/luaVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ static int lua_init(lua_State *L){

SceAvPlayerInitData init_data;
memset(&init_data, 0, sizeof(SceAvPlayerInitData));
init_data.memoryReplacement.allocate = memalloc;
init_data.memoryReplacement.deallocate = dealloc;
init_data.memoryReplacement.allocate = memalloc;
init_data.memoryReplacement.deallocate = dealloc;
init_data.memoryReplacement.allocateTexture = gpu_alloc;
init_data.memoryReplacement.deallocateTexture = gpu_dealloc;
init_data.basePriority = 0xA0;
Expand Down

0 comments on commit 906d5de

Please sign in to comment.