Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Runtime touch listener
Started by novelda76 Jan 16 2019 01:22 AM

6 replies to this topic

Best Answer Appletreeman , 16 January 2019 - 04:31 AM

I would have an invisible object over the top of your video with a touch listener attached.  Then, depending on the x-position of where the object is touched it will either go forwards or backwards.

 

Here's a slightly modified version of your code (variables renamed and composer functions commented out so it can easily be run stand alone).

local function goForward( ... )
  print("---- GOING FORWARDS ----")
  --composer.gotoScene ("pages.scene24", {effect="fromRight", time=400})
end
     
local function goBack( ... )
  print("---- GOING BACKWARDS ----")
  --composer.gotoScene ("pages.scene22", {effect="fromRight", time=400})
end
     
local function touchListener( event )
  if event.phase == "began" then
    if event.x > display.contentWidth/2 then
      goForward()
    else
      goBack()
    end
  end
end


-- Scene event functions
video_040 = native.newVideo( display.contentWidth/2, display.contentHeight/2, display.contentWidth, display.contentHeight)
--video_040.anchorY = 1
      
     
video_040:load( "lom.mp4" )
video_040:play()
    
toucher = display.newRect(0,0,display.contentWidth, display.contentHeight)
toucher.x, toucher.y = display.contentWidth/2, display.contentHeight/2
toucher:addEventListener("touch", touchListener)

local function videoListener(event)
  if event.phase == "ended" then
    video_040:seek(0)  --rewind video after play
    video_040:play()
  end
end
     
video_040:addEventListener( "video", videoListener) 

Hope this helps.

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

novelda76

[GLOBAL: userInfoPane.html]
novelda76
  • Observer

  • 14 posts
  • Corona SDK

Hi, i'm displaying a full screen video in my app. I want the user goes to next or previous scene depending on where the user touches the video object. Can i do that?

 

 
local function goForward( ... )
    composer.gotoScene ("pages.scene24", {effect="fromRight", time=400})
end
 
local function goBack( ... )
    composer.gotoScene ("pages.scene22", {effect="fromRight", time=400})
end
 
 
-- Scene event functions
video_040 = native.newVideo( Scenegroup, common.centerX, common.bottom, common.w, 1820*common.w/1080 )
video_040.anchorY = 1
  
 
video_040:load( "assets/videos/Animation_dontpanic.mp4" )
video_040:play()
 
local function videoListener(event)
        if event.phase == "ended" then
                      video_040:seek(0)  --rewind video after play
                      video_040:play()
          end
      end

video_040:addEventListener( "video", videoListener) 


[TOPIC: post.html]
#2

Appletreeman

[GLOBAL: userInfoPane.html]
Appletreeman
  • Contributor

  • 429 posts
  • Corona SDK

  Best Answer

I would have an invisible object over the top of your video with a touch listener attached.  Then, depending on the x-position of where the object is touched it will either go forwards or backwards.

 

Here's a slightly modified version of your code (variables renamed and composer functions commented out so it can easily be run stand alone).

local function goForward( ... )
  print("---- GOING FORWARDS ----")
  --composer.gotoScene ("pages.scene24", {effect="fromRight", time=400})
end
     
local function goBack( ... )
  print("---- GOING BACKWARDS ----")
  --composer.gotoScene ("pages.scene22", {effect="fromRight", time=400})
end
     
local function touchListener( event )
  if event.phase == "began" then
    if event.x > display.contentWidth/2 then
      goForward()
    else
      goBack()
    end
  end
end


-- Scene event functions
video_040 = native.newVideo( display.contentWidth/2, display.contentHeight/2, display.contentWidth, display.contentHeight)
--video_040.anchorY = 1
      
     
video_040:load( "lom.mp4" )
video_040:play()
    
toucher = display.newRect(0,0,display.contentWidth, display.contentHeight)
toucher.x, toucher.y = display.contentWidth/2, display.contentHeight/2
toucher:addEventListener("touch", touchListener)

local function videoListener(event)
  if event.phase == "ended" then
    video_040:seek(0)  --rewind video after play
    video_040:play()
  end
end
     
video_040:addEventListener( "video", videoListener) 

Hope this helps.



[TOPIC: post.html]
#3

novelda76

[GLOBAL: userInfoPane.html]
novelda76
  • Observer

  • 14 posts
  • Corona SDK

That worked perfectly!!  Thank you so much!!


  • Appletreeman likes this

[TOPIC: post.html]
#4

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 1,967 posts
  • Corona SDK

How can this work when native objects render above openGL (i.e. all your Corona objects)?



[TOPIC: post.html]
#5

Appletreeman

[GLOBAL: userInfoPane.html]
Appletreeman
  • Contributor

  • 429 posts
  • Corona SDK

How can this work when native objects render above openGL (i.e. all your Corona objects)?

Dunno, but it does :)



[TOPIC: post.html]
#6

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 342 posts
  • Corona SDK

Native objects render on top, but user events still bubble to the lower layers.

Check out the sample code for the stop() function of our custom camera preview plugin - https://corona.qweb.co.uk/plugin-android-custom-camera-preview#stop

When the preview is started, the plugin renders a native camera preview in full screen, but the sample code then draws a standard display object to capture tap events and subsequently fire a stop() call to the plugin. It's a pretty nifty trick really.

[TOPIC: post.html]
#7

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 1,967 posts
  • Corona SDK

Everyday is a school day!


[topic_controls]
[/topic_controls]