<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TouchCentric &#187; mptvoutwindow</title>
	<atom:link href="http://www.touchcentric.com/blog/archives/tag/mptvoutwindow/feed" rel="self" type="application/rss+xml" />
	<link>http://www.touchcentric.com/blog</link>
	<description>iPhone-centric stuff we're thinking about</description>
	<lastBuildDate>Wed, 25 Aug 2010 17:09:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>iPhone App Video Mirroring</title>
		<link>http://www.touchcentric.com/blog/archives/3</link>
		<comments>http://www.touchcentric.com/blog/archives/3#comments</comments>
		<pubDate>Fri, 15 May 2009 20:51:08 +0000</pubDate>
		<dc:creator>Rob Terrell</dc:creator>
				<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[iPhone Development]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[iphonesdk]]></category>
		<category><![CDATA[mptvoutwindow]]></category>

		<guid isPermaLink="false">http://www.touchcentric.com/blog/?p=3</guid>
		<description><![CDATA[<p>How can you show your app to a large group? What if you want to show an app to a client, an investor, or at a trade show? Extensive Googling reveals lots of people asking the question, but no good answer. </p>
<p>I'm the organizer of the <a href="http://www.meetup.com/iPhone-Developers/">Raleigh iPhone Developer's Meetup</a> and it's basically impossible for our group's members to demo their apps. The "crowd people around a phone" method breaks at around four people. And our last meetup had 20 people!</p>
<p>Why can't we be like Steve, using our apps on our phone, with the display projected for all to see?</p>
<img class="size-full wp-image-28" title="iPhone App Video Output" src="http://www.touchcentric.com/blog/wp-content/uploads/2009/05/tvout1.jpg" alt="iPhone app displaying its output on a TV" width="500" />
<p>I have a solution, if you're willing to make a special build of your app that's not meant for the app store. No jailbreaking required! Although a willingness to use private methods is.</p>]]></description>
			<content:encoded><![CDATA[<p>How can you show your app to a large group? What if you want to show an app to a client, an investor, or at a trade show? Extensive Googling reveals lots of people asking the question, but no good answer.</p>
<p>I&#8217;m the organizer of the <a href="http://www.meetup.com/iPhone-Developers/">Raleigh iPhone Developer&#8217;s Meetup</a> and it&#8217;s basically impossible for our group&#8217;s members to demo their apps. The &#8220;crowd people around a phone&#8221; method breaks at around four people. And our last meetup had 20 people!</p>
<p>Why can&#8217;t we be like Steve, using our apps on our phone, with the display projected for all to see?</p>
<p>I have a solution, if you&#8217;re willing to make a special build of your app that&#8217;s not meant for the app store. No jailbreaking required! Although a willingness to use private methods is.</p>
<p><b>Update:</b> There&#8217;s a new version for iOS 4.0 here: <a href="http://www.touchcentric.com/blog/archives/123">http://www.touchcentric.com/blog/archives/123</a></p>
<p><strong>How It Works</strong></p>
<p>Inside the iPhone SDK exists a private API for video output. A class called MPTVOutWindow will display whatever it contains via the video output dock connector. (Thanks to Erica Sadun who discovered this class and figured out how to use it!)</p>
<p>I created a UIApplication category (that is to say, an extension to the existing UIApplication class) that uses MPTVOutWindow to mirror the device display onto the TV display. The goal was to make it seamless &#8212; drop the file into a project, recompile, and go. And it&#8217;s really just that easy, with a couple of caveats.</p>
<p>Caveat #1: apps that use this won&#8217;t be allowed into the App Store. That&#8217;s because it uses a couple of private APIs (the MPTVOutWindow class and UIGetScreenImage()). But since you&#8217;re already an iPhone application developer, creating a private build for your own use is normal.</p>
<p><span style="text-decoration: line-through;">Caveat #2: it doesn&#8217;t copy parts of the screen that belong to OpenGL. The class could be extended to do that, if you needed to.</span></p>
<p>Update: actually, it works fine with OpenGL. I demoed an OpenGL game using this at about 20 fps.</p>
<p><strong>Getting Started</strong></p>
<p>First, get a video out cable. It&#8217;s the same cable you&#8217;d use to watch videos from your iPhone on a TV using the dock connector (note: headphone-jack video cables from older iPods do not work). Apple&#8217;s official cable, <a href="http://store.apple.com/us/product/MB128LL/B?fnode=MTY1NDAzOQ&amp;mco=MjE1NTI2OA">Apple Component AV Cable</a>, is $50 for composite video. A similar cable is only $14.18 at <a href="http://www.monoprice.com/products/product.asp?c_id=108&amp;cp_id=10831&amp;cs_id=1083105&amp;p_id=4825&amp;seq=1&amp;format=2">MonoPrice.com</a>. Component cables are also available.<span style="white-space: pre;"> </span>`</p>
<p><strong>How To Use</strong></p>
<p>Add the file UIApplication+TVOut.m to your project. Also, you&#8217;ll need the &#8220;MediaPlayer.framework&#8221; framework, which contains references to the private API we&#8217;re using.</p>
<p>Somewhere in your code you need to call start. Anytime <strong>after </strong>your app&#8217;s primary window has been created, call startTVOut:</p>
<div>
<pre><code>     [[UIApplication] sharedApplication] startTVOut];
</code></pre>
</div>
<p>That&#8217;s about all you need to do. The application category handles everything necessary to mirror the device&#8217;s display. The startTVOut method creates the MPTVoutWindow, adds the necessary subviews, rotates them to match your app&#8217;s orientation, and centers them to appear properly on the TV. A background thread copies the bits from your main display into a view in the MPTVOutWindow. (You can configure the frames per second in the #define at the top of the file. 12 fps works well for me.)</p>
<div id="attachment_28" class="wp-caption alignnone" style="width: 624px"><img class="size-full wp-image-28 " title="iPhone App Video Output" src="http://www.touchcentric.com/blog/wp-content/uploads/2009/05/tvout1.jpg" alt="iPhone app displaying its output on a TV" width="614" height="461" /><p class="wp-caption-text">iPhone app displaying its output on a TV</p></div>
<p>In my test app, I call it from applicationDidFinishLaunching:. One thing to remember about applicationDidFinishLaunching: is that it gets called before the runloop starts, so your primary window isn&#8217;t on screen yet. I call it with a brief delay to give the runloop a chance to get going.</p>
<pre><code>- (void)applicationDidFinishLaunching:(UIApplication*)application {<span>	</span>
// give the runloop a chance to start
    [[UIApplication sharedApplication] performSelector: @selector(startTVOut)
    withObject: nil afterDelay: .1];
}</code></pre>
<p>And actually, you don&#8217;t even need to call startTVOut. The category can start itself. The code includes an override for a private method called reportAppLaunchFinished:. This undocumented method seems to get called after the app has finished loading. (Being undocumented, I&#8217;m not really sure what it does, or what the negative consequences of overriding it has. As far as I can tell, it&#8217;s only used to clean up the Default.png display.) I&#8217;ve commented out that method, since it&#8217;s a bit mysterious. But if you uncomment the method, it will automatically start the TV out display for you. No changes to your code needed!</p>
<p><strong>Mirroring Other Apps?</strong></p>
<p>Since this code runs as part of your app, it stops running when your app stops running. So it&#8217;s not a general purpose full-time video mirroring solution.</p>
<p>However, using other private methods, it&#8217;s possible to launch other apps while your app remains running, thus mirroring whatever app is in front. I&#8217;ve managed to mirror Safari (launched using the private openURL:asPanel: method). I&#8217;m sure you can figure ways to mirror other apps using some of the private app launching methods.</p>
<p><strong>Not for Public Consumption!</strong></p>
<p>Since this uses private methods, it would almost certainly not survive Apple&#8217;s app review process. To avoid getting your app rejected, you should remove this code from your release builds. This is pretty easy &#8212; set the current target to Release and uncheck the checkbox next to the file&#8217;s name. Also, if you call startTVOut manually, you&#8217;ll need to put some #ifdefs around that call, so it won&#8217;t get compiled into release builds.</p>
<p><strong>Great, Where&#8217;s the Code?</strong></p>
<p>Grab the latest code from here:</p>
<p><a onclick="javascript: pageTracker._trackPageview('http://groups.google.com/group/iphone-developers-nc/web/UIApplication_TVOut.m');" href="http://groups.google.com/group/iphone-developers-nc/web/UIApplication_TVOut.m">http://groups.google.com/group/iphone-developers-nc/web/UIApplication_TVOut.m</a></p>
<p>If you have any comments or questions, feel free to email me.</p>
<p>&#8211; Rob</p>
]]></content:encoded>
			<wfw:commentRss>http://www.touchcentric.com/blog/archives/3/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>
