<?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>NightIrion &#187; development</title>
	<atom:link href="http://www.nightirion.com/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nightirion.com</link>
	<description>NightIrion official website</description>
	<lastBuildDate>Wed, 06 Jan 2010 12:13:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Scaling a movie on the iPhone</title>
		<link>http://www.nightirion.com/2010/01/scaling-a-movie-on-the-iphone/</link>
		<comments>http://www.nightirion.com/2010/01/scaling-a-movie-on-the-iphone/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 09:47:27 +0000</pubDate>
		<dc:creator>Ivan Galic</dc:creator>
				<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://www.nightirion.com/?p=184</guid>
		<description><![CDATA[
			
				
			
		
Recently, I&#8217;ve needed to figure out a way how to play a movie on the iPhone in a non-fullscreen mode. So I have a video file and I need to play it on just a part of the screen, just as if it was any other view. I&#8217;ve searched the Internet but couldn&#8217;t find anything [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.nightirion.com%2F2010%2F01%2Fscaling-a-movie-on-the-iphone%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.nightirion.com%2F2010%2F01%2Fscaling-a-movie-on-the-iphone%2F&amp;source=nightirion&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;"><a href="http://www.nightirion.com/wp-content/uploads/2010/01/lightbulb.png"><img class="alignleft size-full wp-image-183" title="lightbulb" src="http://www.nightirion.com/wp-content/uploads/2010/01/lightbulb.png" alt="" width="63" height="63" /></a>Recently, I&#8217;ve needed to figure out a way how to play a movie on the iPhone in a non-fullscreen mode. So I have a video file and I need to play it on just a part of the screen, just as if it was any other view. I&#8217;ve searched the Internet but couldn&#8217;t find anything that would do all I needed. Most of the answers to this question simply stated it&#8217;s not possible with the current SDK. I&#8217;ve found a method using private APIs which is not an option because we need to have this approved on the AppStore. Another idea suggested rolling our own software decoder to play the video. That was also not an option because it would be too CPU-intensive, require too much work and be too hard on the battery.</p>
<p style="text-align: justify;">I was about to give up when I found the answer in a place where I expected it the least &#8211; an official Apple example.</p>
<p style="text-align: justify;"><span id="more-184"></span>Well, what the example really does is it shows how to add custom controls on top of a movie. The way it&#8217;s done seems more like a workaround than the way it was designed to work, but it&#8217;s better than nothing <img src='http://www.nightirion.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p style="text-align: justify;">The idea is to create the movie player, then get a list of windows in the application and the &#8220;key&#8221; window is our movie player. Here is the code from the Apple example:</p>
<div class="geshi no objc">
<ol>
<li class="li1">
<div class="de1"><span class="kw5">NSArray</span> <span class="sy0">*</span>windows <span class="sy0">=</span> <span class="br0">&#91;</span><span class="br0">&#91;</span>UIApplication sharedApplication<span class="br0">&#93;</span> windows<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">UIWindow <span class="sy0">*</span>moviePlayerWindow <span class="sy0">=</span> <span class="kw2">nil</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span><span class="br0">&#91;</span>windows count<span class="br0">&#93;</span> &gt; <span class="nu0">1</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; moviePlayerWindow <span class="sy0">=</span> <span class="br0">&#91;</span><span class="br0">&#91;</span>UIApplication sharedApplication<span class="br0">&#93;</span> keyWindow<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p style="text-align: justify;">From here, you can easily add your own subviews to the moviePlayerWindow. However, that&#8217;s not exactly what I&#8217;ve promised.</p>
<p style="text-align: justify;">Now resizing the window didn&#8217;t quite work as expected. Trying to set the bounds or frame only changes the center of the window, but doesn&#8217;t really affect the size of the movie.</p>
<p style="text-align: justify;">There is one property though that works pretty well &#8211; the window&#8217;s transform. So here is the code:</p>
<div class="geshi no objc">
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>moviePlayerWindow setTransform<span class="sy0">:</span>CGAffineTransformMakeScale<span class="br0">&#40;</span><span class="nu0">0.5</span>, <span class="nu0">0.5</span><span class="br0">&#41;</span><span class="br0">&#93;</span>;</div>
</li>
</ol>
</div>
<p style="text-align: justify;">You could also rotate the video the same way. Also, you can still add your custom controls to this window and it works great (note though that they will be transformed too). There is only one problem: it seems the movie player somehow messes up the status bar so it becomes completely white &#8211; I haven&#8217;t yet been able to fix that but hopefully you can work around it by placing your movie above it or simply hiding it.</p>
<p style="text-align: justify;">I hope this has saved you some time and let me know if you have any comments/suggestions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nightirion.com/2010/01/scaling-a-movie-on-the-iphone/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
