<?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>A Twofer &#187; MPMoviePlayerController</title>
	<atom:link href="http://www.atwofer.com/category/mpmovieplayercontroller/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.atwofer.com</link>
	<description>A place to talk about Software Development (RoR, J2EE, J2ME, CSS, HTML, JavaScript, Objective-C, etc) and some other stuff</description>
	<lastBuildDate>Fri, 16 Jul 2010 14:56:02 +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>Handling redirects with initWithContentURL</title>
		<link>http://www.atwofer.com/2009/08/13/handling-redirects-with-initwithcontenturl/</link>
		<comments>http://www.atwofer.com/2009/08/13/handling-redirects-with-initwithcontenturl/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 17:00:03 +0000</pubDate>
		<dc:creator>Randy</dc:creator>
				<category><![CDATA[MPMoviePlayerController]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[head request]]></category>
		<category><![CDATA[initWithContentURL]]></category>
		<category><![CDATA[initWithURL]]></category>
		<category><![CDATA[NSURLConnection]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[Redirects]]></category>

		<guid isPermaLink="false">http://www.atwofer.com/?p=118</guid>
		<description><![CDATA[I keep running into this problem so I thought that I should post my solution.  There are some classes in the iPhone SDK like the MPMoviePlayerController that have an initWithContentURL method. However, the problem is that the URL I have is one that may issue a redirect response when requested.  When I provide [...]]]></description>
			<content:encoded><![CDATA[<p>I keep running into this problem so I thought that I should post my solution.  There are some classes in the iPhone SDK like the MPMoviePlayerController that have an initWithContentURL method. However, the problem is that the URL I have is one that may issue a redirect response when requested.  When I provide such a URL to initWithContentURL the player tells me that it cannot play me file.  To work around this problem I wrote some very simple code.</p>
<p>The first thing you need to do is to build a HEAD request using NSMutableURLRequest.  Then create an NSURLConnection settings the delegate as the current instance.</p>
<p><code><br />
<span>NSMutableURLRequest *headRequest = </span><br />
<span style="padding-left: 40px">[NSMutableURLRequest requestWithURL:resourceURL</span><br />
<span style="padding-left: 40px">cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];</span><br />
<span> </span><br />
<span style="padding-left: 0px">[headRequest setHTTPMethod:@"HEAD"];</span><br />
<span> </span><br />
<span style="padding-left: 0px">connection = [[NSURLConnection alloc] </span><br />
<span style="padding-left: 40px">initWithRequest:headRequest delegate:self];</span><br />
</code></p>
<p>Now we just need to implement the delegate method to play the URL from the response.</p>
<p><code><br />
<span style="padding-left: 0px">- (void)connection:(NSURLConnection *)connection </span><br />
<span style="padding-left: 40px">didReceiveResponse:(NSURLResponse *)response {</span><br />
<span> </span><br />
<span style="padding-left: 20px">// Now we have resolved the URL so play the movie</span><br />
<span style="padding-left: 20px">thePlayer = [[MPMoviePlayerController alloc] </span><br />
<span style="padding-left: 40px">initWithContentURL:[response URL]];</span><br />
<span> </span><br />
<span style="padding-left: 20px">[thePlayer play];</span><br />
<span style="padding-left: 0px">}</span><br />
</code></p>
<p>Obviously, this example handles one redirect but you can see that you can easily have it loop and until [response statusCode] == 200.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.atwofer.com/2009/08/13/handling-redirects-with-initwithcontenturl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
