Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Apple TV Remote in simulator
Started by funkyvisions Dec 28 2015 11:23 AM

17 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

funkyvisions

[GLOBAL: userInfoPane.html]
funkyvisions
  • Contributor

  • 105 posts
  • Corona SDK

I've started to get one of my games to work on tvOS.  I've got the main menu up and now I want to respond to the Apple TV remote.  I've created a "key" listener, but it never seems to get triggered.  Is there anything special I need to do?  Perhaps my misunderstanding of the remote pad in the simulator?  I can navigate around the "settings" of the Apple TV, but as soon as I launch my app (or pew pew) I seem to lose control except for the menu button exiting.  Ideas what to look for?

 

BTW... nice job with the Apple TV support thus far.  Haven't really had to change much (although is gameNetwork going to be supported?).

 

Thanks,

doug



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,913 posts
  • Enterprise

There are issues with the Up/Down/Left/Right key events so we have pulled those. The other key events work just fine. We are working on a solution to convert axes data to discrete events.

 

Stay tuned.

 

Rob



[TOPIC: post.html]
#3

funkyvisions

[GLOBAL: userInfoPane.html]
funkyvisions
  • Contributor

  • 105 posts
  • Corona SDK

Thanks Rob. I don't even see events for the menu or play/pause button nor just pushing/tapping the touch area.  So I still think I am doing something wrong.  I've looked at all the examples and as far as I can tell I should be doing it properly.

 



[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,913 posts
  • Enterprise

How are you testing this?

 

Rob



[TOPIC: post.html]
#5

funkyvisions

[GLOBAL: userInfoPane.html]
funkyvisions
  • Contributor

  • 105 posts
  • Corona SDK

local function onKeyEvent(event)
	composer.gotoScene("game")
end	

Runtime:addEventListener( "key", onKeyEvent )

Right now I'm just trying to get ANY key to transition to my game scene.  I never see onKeyEvent get called.  I know it's one of those things where I'm doing something stupid and just haven't seen it yet.  ;)

 

I'm building for the 9.1 tvOS simulator and testing there by bringing up the remote and simulating a click on the pad (or hitting play/pause, etc.)

 

Perhaps I should ship it over to my real device with TestFlight.



[TOPIC: post.html]
#6

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,913 posts
  • Enterprise

I would recommend testing on the real device. We know that the Xcode tvOS simulator doesn't make good use of the remote.

 

You can tether the AppleTV to  your Mac using the provided USB-C cable and have Corona install it on the device for you. That's how I test.

 

Rob



[TOPIC: post.html]
#7

JonPM

[GLOBAL: userInfoPane.html]
JonPM
  • Corona Geek

  • 1,077 posts
  • Corona SDK

I would recommend testing on the real device. We know that the Xcode tvOS simulator doesn't make good use of the remote.

 

You can tether the AppleTV to  your Mac using the provided USB-C cable and have Corona install it on the device for you. That's how I test.

 

Rob

 

The retail version of Apple TV doesn't include the USB-C cable (at least mine didn't).  I got mine on Amazon.



[TOPIC: post.html]
#8

funkyvisions

[GLOBAL: userInfoPane.html]
funkyvisions
  • Contributor

  • 105 posts
  • Corona SDK

I transferred my app to the Apple TV via TestFlight and still no go, so I'm pretty sure I'm doing something I'm just not seeing.  I even rolled back to Corona 2795 to no avail.  Once I figure it out I'll report what I did stupid here. :)



[TOPIC: post.html]
#9

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,913 posts
  • Enterprise

I would put some print statements in your listener to see if it's firing and what you're getting.

 

Rob



[TOPIC: post.html]
#10

funkyvisions

[GLOBAL: userInfoPane.html]
funkyvisions
  • Contributor

  • 105 posts
  • Corona SDK

I've stripped my app down to just the following main.lua (in addition to build.settings, config.lua, and all the tvOS icons).

local function onKeyEvent(event)
	print("onKeyEvent")
end	

print("setting up key event listener")
system.activate("controllerUserInteraction")
Runtime:addEventListener( "key", onKeyEvent )

When I run in the Corona simulator I see the key event occur and everything works properly, but when I then build for the tvOS simulator and run it, I see the "setting up key event listener" message but I never see "onKeyEvent" for any remote input (using the virtual remote the apple simulator provides).

 

And earlier I tried on my real device by making ANY key advance to the next scene (because I wasn't sure how to capture the print statements).

 

Am I just missing something basic here or is the a possibility there is an issue with Apple's tvOS simulator?  I can use the keyboard (arrows, enter, space) to navigate around the "settings" menu on the tvOS simulator, so it appears it handles keys appropriately.

 

Sorry for the confusion.  Spent most the day on this and haven't really gotten anywhere.

 



[TOPIC: post.html]
#11

funkyvisions

[GLOBAL: userInfoPane.html]
funkyvisions
  • Contributor

  • 105 posts
  • Corona SDK

I decided to try a straight Xcode project and see if it worked.  I found a simple one at

 

http://www.appcoda.com/tvos-introduction/

 

https://www.dropbox.com/sh/83i9ahb3nabc698/AACEmZp3ikCC3KB_2ZTTQlkNa/HelloWorld?dl=0

 

When I run it under the tvOS simulator I can use the ENTER key and the virtual remote to click the button.  So I don't think there is anything wrong with my environment.  It's just something about a Corona App and key events not getting through.

 

I see other threads on here of people successfully getting key events, but it's unclear as to whether they are using the corona simulator, the tvOS simulator, or the real device.  The only place I've gotten key events is the corona simulator.

 

Thanks,

doug

 



[TOPIC: post.html]
#12

funkyvisions

[GLOBAL: userInfoPane.html]
funkyvisions
  • Contributor

  • 105 posts
  • Corona SDK

I was rereading the documentation at 

 

https://docs.coronalabs.com/daily/guide/tvos/index.html

 

Attached File  Screen Shot 2015-12-29 at 4.00.45 PM.png   75.82KB   0 downloads

 

Maybe I'm misunderstanding something.  The wording is unclear.  Does this mean I MUST HAVE a MFi controller to test in the Corona Simulator?  And where does Corona Enterprise fit into all of this?  Why is it mentioned under the testing with tvOS/Xcode simulator?

 

Confused.

 

Doug

 



[TOPIC: post.html]
#13

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,913 posts
  • Enterprise

I've heard that you can pair your Apple TV remote with OS X at which it should work with the Corona Simulator. But it can't be paired with two devices at once.

 

Apple's Xcode simulator includes a window that does some remote basics, but its very limited in what it can do.

 

That's why I asked "How" you were testing this. If you're remote is paired with the AppleTV you can't get the events in the Simulator. You have to test on the device.

 

I'm unsure why that note is under Enterprise, other than the Xcode simulator would be the natural way to test Enterprise builds if you're not doing device testing. Where as for the SDK you can do a lot in the simulator.

 

What I do is process the OS X keyboard for Up/Down/Left/Right events. I capture the Return/Enter key to act like the  buttonA event:

local function onKeyEvent( event )
	phase = event.phase
	keyName = event.keyName
	print( event.phase, event.keyName )

	if (keyName == "buttonStart" or keyName == "escape" or keyName == "menu") and phase == "down" then
		print( "Going Back" )
		goMenu()
		return true
	elseif ( keyName == "buttonA" or keyName == "enter") and phase == "down" then
		print( "Trying to start level" )
                playLevel()
        return true
    end
    return true
end

Be aware we've removed Up/Down/Left/Right events from the touch sensitive pad on the remote  because of excessive events and you should use the Axis events to detect swiping. There is another thread covering this.

 

Rob



[TOPIC: post.html]
#14

funkyvisions

[GLOBAL: userInfoPane.html]
funkyvisions
  • Contributor

  • 105 posts
  • Corona SDK

Thanks Rob.  Guess I will use the Corona Simulator and do the translation as you suggest.  I did TestFlight Pew Pew to my Apple TV and it works, so definitely something I'm doing wrong in my code.  I think I'm gonna buy another Apple TV I can hook up directly, since this TestFlight process is slow (and I have an upload stuck in processing now that never completed).  Thanks for the help.  Hoping to get my game out there in the next few months.



[TOPIC: post.html]
#15

funkyvisions

[GLOBAL: userInfoPane.html]
funkyvisions
  • Contributor

  • 105 posts
  • Corona SDK

Yep, turns out my bad!  The scene was refusing to transition because of a require error.  I put an alert in on a key event and it's showing.  And of course on the Xcode simulator none of the key events get through as specified on the corona tv os guide.  So... I either need to get a MFi remote for my Mac or another Apple TV that I can hook up directly to see log messages, otherwise it's going to be a pain.  Thanks for all the help.



[TOPIC: post.html]
#16

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,913 posts
  • Enterprise

Why can't you hook up the one you have? Surely an USB-C cable and a USB extension cable to reach across the room would be cheaper than a second AppleTV (which is what I do)



[TOPIC: post.html]
#17

funkyvisions

[GLOBAL: userInfoPane.html]
funkyvisions
  • Contributor

  • 105 posts
  • Corona SDK

Because I need an excuse to buy another one! I already have 3 3rd gens in the house and the 4th gen is downstairs nowhere near my computer. The new one I buy will be for development and then move down into the gym since there are so many good workout apps.

[TOPIC: post.html]
#18

funkyvisions

[GLOBAL: userInfoPane.html]
funkyvisions
  • Contributor

  • 105 posts
  • Corona SDK

I paired my 4th gen Apple TV remote with my Mac.  However it's still unable to control the Corona built app.  The remote does control the rest of the simulator (I can move through the menu settings).  So it looks like the only way to test is with the real device.  That really stinks. :(




[topic_controls]
[/topic_controls]