<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Pocket Journey</title>
	<atom:link href="http://blog.pocketjourney.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pocketjourney.com</link>
	<description>Know Anywhere</description>
	<lastBuildDate>Fri, 12 Mar 2010 16:00:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.pocketjourney.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/343600638c2a4cd57253df5966dc072d?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>Pocket Journey</title>
		<link>http://blog.pocketjourney.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.pocketjourney.com/osd.xml" title="Pocket Journey" />
	<atom:link rel='hub' href='http://blog.pocketjourney.com/?pushpress=hub'/>
		<item>
		<title>Android Map Tutorials Updated to v1.5 (Cupcake) &#8211; MapView &amp; MapActivity</title>
		<link>http://blog.pocketjourney.com/2009/12/27/android-map-tutorials-updated-to-v1-5-cupcake-mapview-mapactivity/</link>
		<comments>http://blog.pocketjourney.com/2009/12/27/android-map-tutorials-updated-to-v1-5-cupcake-mapview-mapactivity/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 18:16:15 +0000</pubDate>
		<dc:creator>Biosopher</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.pocketjourney.com/?p=84</guid>
		<description><![CDATA[I updated the map tutorials to v1.5 as well.  There were enough tricky challenges to getting maps working on Android that I thought it best to pass the information along. Here are the source files for this tutorial as well as all my other tutorials. Tutorial 1: Transparent Panel (Linear Layout) On MapView (Google Map) Tutorial 2: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=84&subd=pocketjourney&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I updated the map tutorials to v1.5 as well.  There were enough tricky challenges to getting maps working on Android that I thought it best to pass the information along. Here are the <a href="http://www.pocketjourney.com/downloads/pj/tutorials/tutorials_1.5.zip">source files for this tutorial</a> as well as all my other tutorials.</p>
<p><a title="Permanent Link to &quot;Tutorial 1: Transparent Panel (Linear Layout) On MapView (Google Map)&quot;" rel="bookmark" href="http://blog.pocketjourney.com/2008/03/15/tutorial-1-transparent-panel-linear-layout-on-mapview-google-map/">Tutorial 1: Transparent Panel (Linear Layout) On MapView (Google Map)</a><br />
<a title="Permanent Link to &quot;Android Tutorial 2: “Hit” testing on a View (MapView)&quot;" rel="bookmark" href="http://blog.pocketjourney.com/2008/03/19/tutorial-2-mapview-google-map-hit-testing-for-display-of-popup-windows/">Tutorial 2: “Hit” testing on a View (MapView)</a></p>
<p>The first challenge to using Google&#8217;s Maps in Android is simply informing Eclipse that you&#8217;ll need access to Google&#8217;s mapping API.  Instead of writing my own tutorial on this, I&#8217;ll simply point you to the same well-documented <a href="http://www.anddev.org/viewtopic.php?p=24902#24902">Android v1.5 MapActivity setup</a> that I followed.</p>
<p>The second challenge as always is getting your Map API key to function properly. Google provides <a href="http://code.google.com/android/add-ons/google-apis/mapkey.html">full details on installing your Google Map key</a>.  I spent several hours trying to figure out why my API key wasn&#8217;t working though&#8230;my Google maps always displayed as empty white/gray tiles.  Eventually I tracked the problem down to the fact that Android had created multiple debug.keystore files on my computer.  I&#8217;m running Vista so my .keystores were located in both of these directories:</p>
<p>Incorrect: <span style="text-decoration:line-through;">C:\Users\acopernicus\AppData\Local\Android\debug.keystore<br />
</span><span style="color:#339966;"><strong>Correct: </strong></span><span style="color:#339966;">C:\users\&lt;username&gt;\.android\debug.keystore</span></p>
<p><span style="color:#339966;"><span style="color:#000000;">I wasted time by using the .keystore in my AppData folder as this was the original place where the .keystores were stored in Android v1.0.  However it now seems that Android now uses the .android directory instead.  If you have problems, figure out which directory Eclipse is pulling your .keystore from when signing your apps.</span><br />
</span><span style="color:#339966;"> </span></p>
<br />Posted in Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pocketjourney.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pocketjourney.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pocketjourney.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pocketjourney.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pocketjourney.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pocketjourney.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pocketjourney.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pocketjourney.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pocketjourney.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pocketjourney.wordpress.com/84/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=84&subd=pocketjourney&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.pocketjourney.com/2009/12/27/android-map-tutorials-updated-to-v1-5-cupcake-mapview-mapactivity/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9d07abb76faa58b0d506b3fa5bc03804?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Biosopher</media:title>
		</media:content>
	</item>
		<item>
		<title>Android Streaming MediaPlayer Tutorial &#8211; Updated to v1.5 (Cupcake)</title>
		<link>http://blog.pocketjourney.com/2009/12/27/android-streaming-mediaplayer-tutorial-updated-to-v1-5-cupcake/</link>
		<comments>http://blog.pocketjourney.com/2009/12/27/android-streaming-mediaplayer-tutorial-updated-to-v1-5-cupcake/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 17:29:56 +0000</pubDate>
		<dc:creator>Biosopher</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.pocketjourney.com/?p=68</guid>
		<description><![CDATA[After spending the last year game programming on the iPhone, I&#8217;ve finally returned to Android.  My six prior tutorials were outdated (Android v1.0) so I took the time to update them to v1.5 (Cupcake).  The most popular of those tutorials was the Streaming MediaPlayer tutorial so that&#8217;s the primary focus of this post.  At the time of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=68&subd=pocketjourney&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>After spending the last year game programming on the iPhone, I&#8217;ve finally returned to Android.  My six prior tutorials were outdated (Android v1.0) so I took the time to update them to v1.5 (Cupcake).  The most popular of those tutorials was the Streaming MediaPlayer tutorial so that&#8217;s the primary focus of this post. </p>
<p><img src="http://pocketjourney.files.wordpress.com/2008/04/tutorial-3-results-screenshots.gif?w=500" border="0" alt="Tutorial #3 results screenshots" /></p>
<p>At the time of initially writing the streaming tutorial, Android&#8217;s media streaming function didn&#8217;t work well so I wrote my own.  As of v1.5 however, Android&#8217;s MediaPlayer streams very well.  That said, it&#8217;s still useful to know how to retrieve a media file from a server and store it on the device.  This would be useful to immediate replay of the file at a later date or for caching files for later playback &#8216;off the grid&#8217;.</p>
<p><a href="http://www.pocketjourney.com/downloads/pj/tutorials/tutorials_1.5.zip">Download the source files</a> to get started immediately and then view the rest of the tutorial after the jump.</p>
<p><span id="more-68"></span></p>
<p>You may want to look at my <a href="http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/">old Android v1.0 streaming tutorial</a> for additional details. I don&#8217;t want to rewrite that post completely so I&#8217;ll mostly focus here on the changes required for Android v1.5.  That said, there is very little difference between my old tutorial and this new one.</p>
<p>The most important change is that MediaPlayer.setDataSource() now takes a FileDescriptor instead of a String path to the media File.  It seems the reason to use FileDescriptors is for security/permission reasons.  In either case though, passing a String path to our media File resulted in errors such as &#8220;PVMFErrNotSupported&#8221; and &#8220;Prepare failed.: status=0&#215;1&#8243;.  So until I learn otherwise, I recommend using FileDescriptor for the MediaPlayer.</p>
<p><code><br />
	FileInputStream fis = new FileInputStream(mediaFile);<br />
	mPlayer.setDataSource(fis.getFD());<br />
</code></p>
<p>The only other change is I can no longer find any File move functionality it Android so I wrote my own.  It does exactly what it says, it moves data in one File to a new File location.  This is used while streaming the media file so we can double buffer it.  The double buffering allows us to simulaneously download to one File while playing from another File.  We sync the downloaded data between the Files as more data is downloaded:</p>
<p><code>public void moveFile(File oldLocation, File newLocation) throws IOException</code></p>
<p><a href="http://www.pocketjourney.com/downloads/pj/tutorials/tutorials_1.5.zip">Download the source files</a> for all the tutorials.  The streaming media tutorial available by clicking button #3.  Don&#8217;t forget to look at my <a href="http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/">old Android v1.0 streaming tutorial</a> for additional details. </p>
<br />Posted in Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pocketjourney.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pocketjourney.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pocketjourney.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pocketjourney.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pocketjourney.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pocketjourney.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pocketjourney.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pocketjourney.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pocketjourney.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pocketjourney.wordpress.com/68/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=68&subd=pocketjourney&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.pocketjourney.com/2009/12/27/android-streaming-mediaplayer-tutorial-updated-to-v1-5-cupcake/feed/</wfw:commentRss>
		<slash:comments>65</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9d07abb76faa58b0d506b3fa5bc03804?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Biosopher</media:title>
		</media:content>

		<media:content url="http://pocketjourney.files.wordpress.com/2008/04/tutorial-3-results-screenshots.gif" medium="image">
			<media:title type="html">Tutorial #3 results screenshots</media:title>
		</media:content>
	</item>
		<item>
		<title>Android Challenge 1 Round 2</title>
		<link>http://blog.pocketjourney.com/2008/08/05/android-challenge-1-round-2/</link>
		<comments>http://blog.pocketjourney.com/2008/08/05/android-challenge-1-round-2/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 19:05:22 +0000</pubDate>
		<dc:creator>Biosopher</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://pocketjourney.wordpress.com/?p=39</guid>
		<description><![CDATA[First we want to thank everyone for their comments about our prior Android tutorials.  We&#8217;re very glad to have helped you guys.  Many of you have asked why we haven&#8217;t posted new tutorials, and the reason is that happily, we&#8217;ve spent the few months working hard on our submission into Round 2 of Android Challenge [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=39&subd=pocketjourney&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>First we want to thank everyone for their comments about our prior Android tutorials.  We&#8217;re very glad to have helped you guys.  Many of you have asked why we haven&#8217;t posted new tutorials, and the reason is that happily, we&#8217;ve spent the few months working hard on our submission into Round 2 of Android Challenge #1.  Yes&#8230;if you hadn&#8217;t heard already, we were one of the top 50 finalists.</p>
<p>As soon as Google releases the next SDK, we&#8217;ll write up more tutorials based on the lessons we&#8217;ve learned over the past months.</p>
<p>Until then, we&#8217;re getting out to exercise and enjoy some sunshine away from our desks.</p>
<p>Cheers,</p>
<p>Anthony (Biosopher)</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pocketjourney.wordpress.com/39/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pocketjourney.wordpress.com/39/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pocketjourney.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pocketjourney.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pocketjourney.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pocketjourney.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pocketjourney.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pocketjourney.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pocketjourney.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pocketjourney.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pocketjourney.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pocketjourney.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=39&subd=pocketjourney&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.pocketjourney.com/2008/08/05/android-challenge-1-round-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9d07abb76faa58b0d506b3fa5bc03804?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Biosopher</media:title>
		</media:content>
	</item>
		<item>
		<title>Android Application Lifecycle Demo</title>
		<link>http://blog.pocketjourney.com/2008/06/05/android-application-lifecycle-demo/</link>
		<comments>http://blog.pocketjourney.com/2008/06/05/android-application-lifecycle-demo/#comments</comments>
		<pubDate>Fri, 06 Jun 2008 00:36:09 +0000</pubDate>
		<dc:creator>Biosopher</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://pocketjourney.wordpress.com/?p=36</guid>
		<description><![CDATA[An excellent video on Android&#8217;s application lifecycle has been posted today by Sleepy Droid: Demo video here I thought I already knew everything about Android&#8217;s app lifecycle, but this visual refresher and sample application were a great refresher. Understanding the application lifecycle is crucial to writing good Android apps so this video shoud be useful to pros [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=36&subd=pocketjourney&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>An excellent video on Android&#8217;s application lifecycle has been posted today by Sleepy Droid:</p>
<p><a title="Android application lifecycle" href="http://blip.tv/file/958450/">Demo video here</a></p>
<p>I thought I already knew everything about Android&#8217;s app lifecycle, but this visual refresher and sample application were a great refresher. Understanding the application lifecycle is crucial to writing good Android apps so this video shoud be useful to pros and newbies alike.</p>
<p><a title="Sleepy Droid" href="http://sleepydroid.blogspot.com">Sleepy Droid</a> says they&#8217;ll be creating more videos if the response is positive so visit Sleepy Droid to see if new videos have been posted.</p>
<p>Thanks Sleepy Droid!</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pocketjourney.wordpress.com/36/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pocketjourney.wordpress.com/36/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pocketjourney.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pocketjourney.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pocketjourney.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pocketjourney.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pocketjourney.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pocketjourney.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pocketjourney.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pocketjourney.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pocketjourney.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pocketjourney.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=36&subd=pocketjourney&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.pocketjourney.com/2008/06/05/android-application-lifecycle-demo/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9d07abb76faa58b0d506b3fa5bc03804?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Biosopher</media:title>
		</media:content>
	</item>
		<item>
		<title>iPhone Getting GPS &amp; SDK Getting Maps API&#8230;?</title>
		<link>http://blog.pocketjourney.com/2008/05/04/iphone-getting-gps-sdk-getting-maps-api/</link>
		<comments>http://blog.pocketjourney.com/2008/05/04/iphone-getting-gps-sdk-getting-maps-api/#comments</comments>
		<pubDate>Mon, 05 May 2008 05:00:31 +0000</pubDate>
		<dc:creator>Biosopher</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[gps]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[SDK]]></category>

		<guid isPermaLink="false">http://pocketjourney.wordpress.com/?p=34</guid>
		<description><![CDATA[Since I dissed the iPhone SDK earlier this month (iPhone SDK lacks mapping function), I wanted to pass on this update. Looks like a GPS-enabled iPhone is in the works for Apple&#8217;s upcoming World Wide Dev Conference. Even if the announcement doesn&#8217;t come then, looks like it will come soon according to EnGadget: Second-gen iPhone: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=34&subd=pocketjourney&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Since I dissed the iPhone SDK earlier this month (<a href="http://blog.pocketjourney.com/2008/04/22/iphone-sdk-lacks-mapping-function-android-doesnt-of-course/">iPhone SDK lacks mapping function</a>), I wanted to pass on this update. Looks like a GPS-enabled iPhone is in the works for Apple&#8217;s upcoming World Wide Dev Conference.  Even if the announcement doesn&#8217;t come then, looks like it will come soon according to EnGadget:</p>
<p><a href="http://www.engadget.com/2008/04/25/the-second-gen-iphone-3g-gps-only-slightly-thicker/">Second-gen iPhone: 3G, GPS, only slightly thicker</a></p>
<p><a title="Old iPhone - see new at Engadget" href="http://www.engadget.com/2008/04/25/the-second-gen-iphone-3g-gps-only-slightly-thicker/"><img class="alignnone size-full wp-image-35" style="border:0 none;" src="http://pocketjourney.files.wordpress.com/2008/05/gps_iphone.gif?w=150&#038;h=105" alt="Click to see new GPS-iPhone at EndGadget" width="150" height="105" /></a></p>
<p>This is great news for mobile map-based application developers but don&#8217;t count on the API being as slick and open as Android&#8217;s.  Given Apple&#8217;s approach so far, they&#8217;ll still withhold the vital functionality to get your app really humming.</p>
<p>Why do I say that?</p>
<p>Well for example, Apple&#8217;s SDK doesn&#8217;t allow applications to run in the background.  That means death to any Pocket Journey app that would run on an iPhone as the audio/video would be killed along with your application as soon as someone called.  Apple says this is for security reasons, but we know it&#8217;s due to Apple&#8217;s &#8220;control freakish&#8221; corporate nature.  Happily for us, Android solved this challenge through their Service API.</p>
<p>Seems like Apple wants to step back to the dark ages of the Palm OS which can only handle single-threaded tasks as well</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pocketjourney.wordpress.com/34/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pocketjourney.wordpress.com/34/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pocketjourney.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pocketjourney.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pocketjourney.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pocketjourney.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pocketjourney.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pocketjourney.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pocketjourney.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pocketjourney.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pocketjourney.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pocketjourney.wordpress.com/34/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=34&subd=pocketjourney&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.pocketjourney.com/2008/05/04/iphone-getting-gps-sdk-getting-maps-api/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9d07abb76faa58b0d506b3fa5bc03804?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Biosopher</media:title>
		</media:content>

		<media:content url="http://pocketjourney.files.wordpress.com/2008/05/gps_iphone.gif" medium="image">
			<media:title type="html">Click to see new GPS-iPhone at EndGadget</media:title>
		</media:content>
	</item>
		<item>
		<title>Android Tutorial #4.2: Passing custom attributes via XML resource files</title>
		<link>http://blog.pocketjourney.com/2008/05/02/android-tutorial-42-passing-custom-variables-via-xml-resource-files/</link>
		<comments>http://blog.pocketjourney.com/2008/05/02/android-tutorial-42-passing-custom-variables-via-xml-resource-files/#comments</comments>
		<pubDate>Fri, 02 May 2008 20:09:19 +0000</pubDate>
		<dc:creator>Biosopher</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://pocketjourney.wordpress.com/?p=33</guid>
		<description><![CDATA[In tutorial #4.1, I mentioned that we passed custom attributes for the text and image variables from the XML resource file to our custom class. This is a critical skill for performing true object-oriented programming and how to do it wasn&#8217;t obvious from Google&#8217;s Android API Demos. Luckily I was pointed to the solution myself [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=33&subd=pocketjourney&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>In tutorial #4.1, I mentioned that we passed custom attributes for the text and image variables from the XML resource file to our custom class. This is a critical skill for performing true object-oriented programming and how to do it wasn&#8217;t obvious from Google&#8217;s Android API Demos.</p>
<p>Luckily I was pointed to the solution myself by an experienced Android programmer in Guatemala by the username of cadlg (thanks again!). If you want to see the official Google Android example though, look at Android&#8217;s APIDemos&#8217; custom LabelView example.</p>
<p>So here we go. We&#8217;ll use the same code as <a href="http://blog.pocketjourney.com/2008/04/30/android-tutorial-image-text-only-buttons/">Tutorial 4.1</a> to keep this simple.</p>
<p><span id="more-33"></span></p>
<p><strong>Setting Up Your Custom Class&#8217;s XML Resource Files</strong></p>
<p>We&#8217;ll only review the code for the TextOnlyButton as it&#8217;s identical in concept to the ImageOnlyButton.</p>
<p>First we&#8217;ll create a new file<span class="postbody"> in /res/values called attrs.xml </span></p>
<p style="padding-left:30px;"><span style="color:#3366ff;">&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;<br />
&lt;resources&gt;</span></p>
<p style="padding-left:60px;"><span style="color:#3366ff;">&lt;declare-styleable name=&#8221;TextOnlyButton&#8221;&gt;</span></p>
<p style="padding-left:90px;"><span style="color:#3366ff;">&lt;attr name=&#8221;textColorNotFocused&#8221; format=&#8221;integer&#8221;/&gt;<br />
&lt;attr name=&#8221;textColorFocused&#8221; format=&#8221;integer&#8221;/&gt;</span></p>
<p style="padding-left:60px;"><span style="color:#3366ff;">&lt;/declare-styleable&gt;</span></p>
<p style="padding-left:30px;"><span style="color:#3366ff;">&lt;/resources&gt;<br />
</span></p>
<p>As you see, we first declared a &#8216;styleable&#8217; with the name of our custom Class. Two attributes were then added to contain the values of our focused &amp; unfocused text colors. By default, attributes have values of String, but in our case, we needed integers to represent the resource id&#8217;s we&#8217;ll declare in our colors.xml file. You can also declare formats such as &#8220;boolean&#8221; &amp; others if that suits the requirements of your own project.</p>
<p>Next, we declare values for these custom attributes in our layout&#8217;s XML file: tutorial4.xml</p>
<p style="padding-left:30px;"><span style="color:#3366ff;">&lt;LinearLayout xmlns:android=&#8221;http://schemas.android.com/apk/res/android&#8221;</span></p>
<p style="padding-left:60px;"><span style="color:#3366ff;"><span style="color:#ff0000;">xmlns:pj=&#8221;http://schemas.android.com/apk/res/com.pocketjourney.tutorials&#8221;</span><br />
android:orientation=&#8221;vertical&#8221;<br />
android:layout_width=&#8221;fill_parent&#8221;<br />
android:layout_height=&#8221;fill_parent&#8221;<br />
android:padding=&#8221;10px&#8221;&gt;<br />
</span></p>
<p style="padding-left:90px;"><span style="color:#3366ff;">&lt;com.pocketjourney.view.TextOnlyButton</span></p>
<p style="padding-left:120px;"><span style="color:#3366ff;">android:id=&#8221;@+id/text_only_button&#8221;<br />
</span><span style="color:#3366ff;">android:layout_width=&#8221;wrap_content&#8221;<br />
</span><span style="color:#3366ff;">android:layout_height=&#8221;wrap_content&#8221;<br />
</span><span style="color:#3366ff;">android:layout_marginTop=&#8221;5px&#8221;<br />
</span><span style="color:#3366ff;">style=&#8221;?android:attr/buttonStyleSmall&#8221;<br />
</span><span style="color:#3366ff;">android:text=&#8221;Text Button&#8221;<br />
</span><span style="color:#ff0000;">pj:textColorNotFocused=&#8221;@drawable/white&#8221;<br />
</span><span style="color:#3366ff;"><span style="color:#ff0000;">pj:textColorFocused=&#8221;@drawable/android_orange&#8221;</span>/&gt;<br />
</span></p>
<p style="padding-left:30px;"><span style="color:#3366ff;">&lt;/LinearLayout&gt;</span></p>
<p>Referring to our new attributes is actually a two step process. First we declared a new namespace (in our case called &#8216;pj&#8217; as short for PocketJourney) in the parent layout of our custom class:</p>
<p style="padding-left:30px;"><span style="color:#3366ff;">xmlns:pj=&#8221;http://schemas.android.com/apk/res/com.pocketjourney.tutorials&#8221;</span></p>
<p>Next we specified the values of our new attributes in the XML usage of our TextOnlyButton:</p>
<p style="padding-left:30px;"><span style="color:#3366ff;">pj:textColorNotFocused=&#8221;@drawable/white&#8221;<br />
</span><span style="color:#3366ff;">pj:textColorFocused=&#8221;@drawable/android_orange&#8221;</span></p>
<p>Now you can see why we specified our format=&#8221;integer&#8221;. Our custom attributes point to the resource id&#8217;s of colors specified in our colors.xml file.</p>
<p><strong>Retrieving Custom Attributes During Class Instantiation</strong></p>
<p>Since our Activity has many constructors, we delegate the attribute parsing to an init() method to keep our code clean.</p>
<p style="padding-left:30px;"><em>int notFocusedTextColor, f</em><em>ocusedTextColor;</em></p>
<p style="padding-left:30px;"><em>private void init(AttributeSet attrs) {</em></p>
<p style="padding-left:60px;"><em>Resources.StyledAttributes a = getContext().obtainStyledAttributes(attrs,<span style="color:#ff0000;">R.styleable.TextOnlyButton</span>);<br />
notFocusedTextColor = a.getColor(<span style="color:#ff0000;">R.styleable.TextOnlyButton_textColorNotFocused</span>, 0xFF000000);<br />
</em><em>focusedTextColor = a.getColor(<span style="color:#ff0000;">R.styleable.TextOnlyButton_textColorFocused</span>, 0xFF000000);</em></p>
<p style="padding-left:30px;">}</p>
<p>By now you&#8217;ve undoubtedly seen the AttributeSet that is always passed into an Activity. Well now you get to use it. First we obtain the StyledAttributes instance by requesting just the StyledAttributes for our custom Class. Next, we call the getColor() and pass two variables: the name of the attribute we want along with a default value in case the user did not specify one.</p>
<p>Take note of our styled attribute&#8217;s name as it&#8217;s a combination of our custom class&#8217;s name and the attribute we specified in the attrs.xml file (e.g. <em>TextOnlyButton_textColorNotFocused).</em></p>
<p><strong>And That&#8217;s It</strong></p>
<p>You can now readily pass your own custom attributes and keep your View variables cleanly enclosed in your XML files. You can download the <a title="tutorial4 zip file" href="http://www.pocketjourney.com/downloads/pj/tutorials/tutorial4.zip">source</a> to see for yourself. Just look at Tutorial #4.</p>
<p><strong>Prior Tutorials</strong></p>
<p><a title="Transparent Panel (Linear Layout) On MapView (Google Map)" rel="bookmark" href="http://blog.pocketjourney.com/2008/03/15/tutorial-1-transparent-panel-linear-layout-on-mapview-google-map/">Tutorial 1: Transparent Panel (Linear Layout) On MapView (Google Map)</a><br />
<a title="Transparent Panel (Linear Layout) On MapView (Google Map)" rel="bookmark" href="http://blog.pocketjourney.com/2008/03/15/tutorial-1-transparent-panel-linear-layout-on-mapview-google-map/">Tutorial 2: </a><a title="“Hit” testing on a View (MapView)" rel="bookmark" href="http://blog.pocketjourney.com/2008/03/19/tutorial-2-mapview-google-map-hit-testing-for-display-of-popup-windows/">“Hit” testing on a View (MapView)</a><br />
<a title="Transparent Panel (Linear Layout) On MapView (Google Map)" rel="bookmark" href="http://blog.pocketjourney.com/2008/03/15/tutorial-1-transparent-panel-linear-layout-on-mapview-google-map/">Tutorial 3: </a><a title="Custom Media Streaming with MediaPlayer" rel="bookmark" href="http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/">Custom Media Streaming with MediaPlayer<br />
</a><a href="http://blog.pocketjourney.com/2008/04/30/android-tutorial-image-text-only-buttons">Tutorial 4.1: Image and Text-Only Buttons</a> <a title="Custom Media Streaming with MediaPlayer" rel="bookmark" href="http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/"><br />
</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pocketjourney.wordpress.com/33/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pocketjourney.wordpress.com/33/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pocketjourney.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pocketjourney.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pocketjourney.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pocketjourney.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pocketjourney.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pocketjourney.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pocketjourney.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pocketjourney.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pocketjourney.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pocketjourney.wordpress.com/33/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=33&subd=pocketjourney&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.pocketjourney.com/2008/05/02/android-tutorial-42-passing-custom-variables-via-xml-resource-files/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9d07abb76faa58b0d506b3fa5bc03804?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Biosopher</media:title>
		</media:content>
	</item>
		<item>
		<title>Android Tutorial #4.1: Image &amp; Text-Only Buttons (UPDATED)</title>
		<link>http://blog.pocketjourney.com/2008/04/30/android-tutorial-image-text-only-buttons/</link>
		<comments>http://blog.pocketjourney.com/2008/04/30/android-tutorial-image-text-only-buttons/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 23:13:21 +0000</pubDate>
		<dc:creator>Biosopher</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://pocketjourney.wordpress.com/?p=31</guid>
		<description><![CDATA[This very simple tutorial will add to your Android UI (user interface) development arsenal. How? Buttons that display as simple text or as images are basic elements of any application. By following the two steps below, these buttons can be easily created with Google&#8217;s Android by simply extending the current Button and ImageButton classes. We [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=31&subd=pocketjourney&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>This very simple tutorial will add to your Android UI (user interface) development arsenal. How? Buttons that display as simple text or as images are basic elements of any application. By following the two steps below, these buttons can be easily created with Google&#8217;s Android by simply extending the current Button and ImageButton classes.</p>
<p>We will create these two new Button extensions as shown:</p>
<p><img class="alignnone size-full wp-image-32" src="http://pocketjourney.files.wordpress.com/2008/04/text_image_buttons.gif?w=138&#038;h=124" alt="Text and Image Buttons" width="138" height="124" /></p>
<p><span id="more-31"></span></p>
<p><strong>Step 1: Set Background to &#8216;null&#8217; in XML or </strong><strong>code </strong></p>
<p>The recommended technique is to use the &#8216;empty&#8217; drawable variable in your ImageButton or TextButton&#8217;s XML to set your background to null:</p>
<p style="padding-left:30px;"><em>android:background=&#8221;@android:drawable/empty&#8221;</em></p>
<p>An optional technique is to extend ImageButton or TextButton and to set the background to null in the constuctor. As above, this is not the recommended approach but may be useful at times:</p>
<p style="padding-left:30px;"><em>public YourButtonExtension() {</em></p>
<p style="padding-left:60px;"><em>setBackground(null);<br />
</em></p>
<p style="padding-left:30px;"><em>}</em></p>
<p>And that&#8217;s it, only your image or text will display but will have button functionality&#8230;except for visually displaying focus. Let&#8217;s address that next.</p>
<p><strong>Step 2: Handle onFocus() by overriding onDraw()</strong></p>
<p>We listen for the focus event and update the Button&#8217;s text color or button image that way as well. But we&#8217;ll do it this way for now.</p>
<p style="padding-left:30px;"><em>public void onDraw(Canvas canvas) {</em></p>
<p style="padding-left:60px;"><span style="color:#339966;"><em>// Since this Button now has no background. We must set the text color to indicate focus.<br />
</em></span><em>if (isFocused()) {</em></p>
<p style="padding-left:90px;"><span style="color:#339966;"><em>// Set the focused text color. In the case of ImageOnlyButton we would .<br />
</em></span><span style="color:#339966;"><em>// instead do setImageResource(imageResourceFocused);</em></span><br />
<em>setTextColor(focusedTextColor);</em></p>
<p style="padding-left:60px;"><em>} else {<br />
</em></p>
<p style="padding-left:90px;"><span style="color:#339966;"><em>// Set the non-focused text color. In the case of ImageOnlyButton we would .<br />
</em></span><span style="color:#339966;"><em>// instead do setImageResource(imageResourceNotFocused);</em></span><br />
<em>setTextColor(notFocusedTextColor);</em></p>
<p style="padding-left:90px;">
<p style="padding-left:60px;"><em>}<br />
</em></p>
<p style="padding-left:60px;"><em>super.onDraw(canvas);<br />
</em></p>
<p style="padding-left:30px;"><em>}</em><span style="color:#000000;"><br />
</span></p>
<p><span style="color:#000000;">You might be wondering where those text color and image variables come from. We will obtain these focused &amp; not-focused images or text colors from variables passed in from the XML resource file as you&#8217;ll see by reading the source code. I won&#8217;t go into how that happens here. Instead, I&#8217;ll keep this tutorial simple and point you to my next tutorial where I will discuss how to create &amp; pass such custom variables.</span></p>
<p><strong>And That&#8217;s It</strong></p>
<p>You can download the <a title="tutorial4 zip file" href="http://www.pocketjourney.com/downloads/pj/tutorials/tutorials_1.5.zip">source</a> to see for yourself.</p>
<p><strong>Prior Tutorials</strong><br />
<a title="Custom Media Streaming with MediaPlayer" rel="bookmark" href="http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/"></a><a title="Transparent Panel (Linear Layout) On MapView (Google Map)" rel="bookmark" href="http://blog.pocketjourney.com/2008/03/15/tutorial-1-transparent-panel-linear-layout-on-mapview-google-map/"></a></p>
<p><a title="Transparent Panel (Linear Layout) On MapView (Google Map)" rel="bookmark" href="http://blog.pocketjourney.com/2008/03/15/tutorial-1-transparent-panel-linear-layout-on-mapview-google-map/">Tutorial 1: Transparent Panel (Linear Layout) On MapView (Google Map)</a><br />
<a title="Transparent Panel (Linear Layout) On MapView (Google Map)" rel="bookmark" href="http://blog.pocketjourney.com/2008/03/15/tutorial-1-transparent-panel-linear-layout-on-mapview-google-map/">Tutorial 2: </a><a title="“Hit” testing on a View (MapView)" rel="bookmark" href="http://blog.pocketjourney.com/2008/03/19/tutorial-2-mapview-google-map-hit-testing-for-display-of-popup-windows/">“Hit” testing on a View (MapView)</a><br />
<a title="Transparent Panel (Linear Layout) On MapView (Google Map)" rel="bookmark" href="http://blog.pocketjourney.com/2008/03/15/tutorial-1-transparent-panel-linear-layout-on-mapview-google-map/">Tutorial 3: </a><a title="Custom Media Streaming with MediaPlayer" rel="bookmark" href="http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/">Custom Media Streaming with MediaPlayer</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pocketjourney.wordpress.com/31/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pocketjourney.wordpress.com/31/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pocketjourney.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pocketjourney.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pocketjourney.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pocketjourney.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pocketjourney.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pocketjourney.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pocketjourney.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pocketjourney.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pocketjourney.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pocketjourney.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=31&subd=pocketjourney&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.pocketjourney.com/2008/04/30/android-tutorial-image-text-only-buttons/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9d07abb76faa58b0d506b3fa5bc03804?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Biosopher</media:title>
		</media:content>

		<media:content url="http://pocketjourney.files.wordpress.com/2008/04/text_image_buttons.gif" medium="image">
			<media:title type="html">Text and Image Buttons</media:title>
		</media:content>
	</item>
		<item>
		<title>iPhone SDK lacks mapping function (Android doesn&#8217;t of course)</title>
		<link>http://blog.pocketjourney.com/2008/04/22/iphone-sdk-lacks-mapping-function-android-doesnt-of-course/</link>
		<comments>http://blog.pocketjourney.com/2008/04/22/iphone-sdk-lacks-mapping-function-android-doesnt-of-course/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 17:35:05 +0000</pubDate>
		<dc:creator>Biosopher</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[gps]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[SDK]]></category>

		<guid isPermaLink="false">http://pocketjourney.wordpress.com/?p=30</guid>
		<description><![CDATA[Here&#8217;s a quick insight from research into the iPhone SDK in comparison to the Android OS. Yes&#8230;you read this post&#8217;s title correctly. The iPhone SDK lacks the basic mapping API required by applications developers hoping to tie the mobile experience to a geo-specific location (GPS). The only GPS mapping function provided by the iPhone SDK [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=30&subd=pocketjourney&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick insight from research into the <a href="http://developer.apple.com/iphone/program/">iPhone SDK</a> in comparison to the <a href="http://code.google.com/android">Android OS</a>.</p>
<p>Yes&#8230;you read this post&#8217;s title correctly.  The iPhone SDK lacks the basic mapping API required by applications developers hoping to tie the mobile experience to a geo-specific location (GPS).  The only GPS mapping function provided by the iPhone SDK is to send a URL to the iPhone&#8217;s built-in Google map application and to let Google handle the rest.</p>
<p>Curiously the iPhone SDK does provide a basic location service API providing the user&#8217;s location using cell signal triangulation, but without a map, this information is all-but-useless.</p>
<p>At first glance you might say, &#8220;that makes sense as the iPhone doesn&#8217;t have GPS built-in because it would have raised the price of an already expensive phone.&#8221;</p>
<p>Point taken but all this leaves me to believe that Apple&#8217;s take on the iPhone is too media focused and lacks clear understanding of the power provided by location-awareness.  That&#8217;s great news for the upcoming GPS-enabled Android phones.  They&#8217;ll have time to widely proliferate before the soon-to-be almost 10M iPhones out there will be replaced with GPS-enabled iPhones.</p>
<p>Imagine if Android had lacked the MapActivity API&#8230;?!?  From my count, 90% of the most interesting Android Challenge entries would never exist.  Without Android&#8217;s MapActivity API, we would be left with a few accelerometer-based games and non-SMS messaging apps.</p>
<p>This is great news for Google and perhaps that&#8217;s the point.  Google wrote the iPhone&#8217;s map application and was either not given incentive to make expose its iPhone map through an API or perhaps decided it was smart to keep the iPhone limited in this crucial manner.  OK&#8230;maybe Apple has a bigger plan as it always does.  Maybe Apple is preparing to launch its own mapping application or perhaps AT&amp;T didn&#8217;t want Apple to expose such location-based apps because AT&amp;T has its own GPS agenda.</p>
<p>Thoughts anyone?</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pocketjourney.wordpress.com/30/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pocketjourney.wordpress.com/30/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pocketjourney.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pocketjourney.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pocketjourney.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pocketjourney.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pocketjourney.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pocketjourney.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pocketjourney.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pocketjourney.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pocketjourney.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pocketjourney.wordpress.com/30/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=30&subd=pocketjourney&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.pocketjourney.com/2008/04/22/iphone-sdk-lacks-mapping-function-android-doesnt-of-course/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9d07abb76faa58b0d506b3fa5bc03804?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Biosopher</media:title>
		</media:content>
	</item>
		<item>
		<title>Android Video &amp; Screenshots Released</title>
		<link>http://blog.pocketjourney.com/2008/04/09/android-video-screenshots-released/</link>
		<comments>http://blog.pocketjourney.com/2008/04/09/android-video-screenshots-released/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 22:03:58 +0000</pubDate>
		<dc:creator>Biosopher</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[challenge]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[location]]></category>
		<category><![CDATA[pocket journey]]></category>
		<category><![CDATA[travel]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://pocketjourney.wordpress.com/?p=24</guid>
		<description><![CDATA[We were inspired by all the great videos presenting other Android-enabled applications being entered into Google&#8217;s Android Challenge so we created a short (4 minute) video about Pocket Journey. You&#8217;ll be shown screen shots in the video or you can view close ups on our main website We&#8217;ve tried to capture what we view as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=24&subd=pocketjourney&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>We were inspired by all the great videos presenting other Android-enabled applications being entered into <a title="Google's Android Challenge" href="http://code.google.com/android/adc.html">Google&#8217;s Android Challenge</a> so we created a short (4 minute) <a title="Pocket Journey Video" href="http://www.pocketjourney.com/androidVideo.do">video about Pocket Journey</a>.</p>
<p><a href="http://www.pocketjourney.com/androidVideo.do"><img class="alignnone size-full wp-image-28" style="border:1px solid black;" src="http://pocketjourney.files.wordpress.com/2008/04/video_splash.gif?w=250&#038;h=166" alt="Video Splash" width="250" height="166" /></a></p>
<p><span id="more-24"></span></p>
<p>You&#8217;ll be shown screen shots in the video or you can view close ups on <a title="Pocket Journey" href="http://www.pocketjourney.com">our main website</a></p>
<p><a href="http://www.pocketjourney.com/androidVideo.do"><img class="alignnone size-medium wp-image-26" src="http://pocketjourney.files.wordpress.com/2008/04/home.gif?w=155&#038;h=300" alt="Pocket Journey home screen" width="155" height="300" /></a></p>
<p>We&#8217;ve tried to capture what we view as the power of community and the interest we&#8217;ve heard around packaging high quality knowledge from a range of people and making it available through mobile phones.</p>
<p><a href="http://www.pocketjourney.com/androidVideo.do"><img class="alignnone size-full wp-image-25" style="border:1px solid black;" src="http://pocketjourney.files.wordpress.com/2008/04/everyones_knowledge.gif?w=500&#038;h=316" alt="Everyone\'s Knowledge" width="500" height="316" /></a></p>
<p>As you can imagine, there will be a broad range of topics provided through Pocket Journey so it will be a major challenge to filter, pacakge, &amp; deliver just the information you want.</p>
<p><a title="Pocket Journey Video" href="http://www.pocketjourney.com/androidVideo.do"><img class="alignnone size-full wp-image-29" style="border:1px solid black;" src="http://pocketjourney.files.wordpress.com/2008/04/world_of_knowledge.gif?w=350&#038;h=246" alt="A world of knowledge" width="350" height="246" /></a></p>
<p>Yes&#8230;this GREATLY simplifies the challenge but we wanted to give you a very very &#8220;rough&#8221; idea of where we&#8217;re headed. We plan to provide more details as the project matures.</p>
<p><a href="http://www.pocketjourney.com/androidVideo.do"><img class="alignnone size-full wp-image-27" style="border:1px solid black;" src="http://pocketjourney.files.wordpress.com/2008/04/pocketjourney_magic.gif?w=350&#038;h=254" alt="How Pocket Journey works - greatly simplified" width="350" height="254" /></a></p>
<p>But don&#8217;t just take these static images as the real message. Check out the <a title="Android Video about Pocket Journey" href="http://www.pocketjourney.com/androidVideo.do">Pocket Journey video</a> to get a much clearer understanding and to actually &#8220;hear&#8221; what it&#8217;s all about. It will only take 4 minutes of your time.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pocketjourney.wordpress.com/24/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pocketjourney.wordpress.com/24/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pocketjourney.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pocketjourney.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pocketjourney.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pocketjourney.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pocketjourney.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pocketjourney.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pocketjourney.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pocketjourney.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pocketjourney.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pocketjourney.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=24&subd=pocketjourney&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.pocketjourney.com/2008/04/09/android-video-screenshots-released/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9d07abb76faa58b0d506b3fa5bc03804?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Biosopher</media:title>
		</media:content>

		<media:content url="http://pocketjourney.files.wordpress.com/2008/04/video_splash.gif" medium="image">
			<media:title type="html">Video Splash</media:title>
		</media:content>

		<media:content url="http://pocketjourney.files.wordpress.com/2008/04/home.gif" medium="image">
			<media:title type="html">Pocket Journey home screen</media:title>
		</media:content>

		<media:content url="http://pocketjourney.files.wordpress.com/2008/04/everyones_knowledge.gif" medium="image">
			<media:title type="html">Everyone\'s Knowledge</media:title>
		</media:content>

		<media:content url="http://pocketjourney.files.wordpress.com/2008/04/world_of_knowledge.gif" medium="image">
			<media:title type="html">A world of knowledge</media:title>
		</media:content>

		<media:content url="http://pocketjourney.files.wordpress.com/2008/04/pocketjourney_magic.gif" medium="image">
			<media:title type="html">How Pocket Journey works - greatly simplified</media:title>
		</media:content>
	</item>
		<item>
		<title>Android Tutorial 3: Custom Audio Streaming with MediaPlayer</title>
		<link>http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/</link>
		<comments>http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/#comments</comments>
		<pubDate>Fri, 04 Apr 2008 23:00:55 +0000</pubDate>
		<dc:creator>Biosopher</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[stream]]></category>
		<category><![CDATA[media]]></category>
		<category><![CDATA[mediaplayer]]></category>
		<category><![CDATA[audio]]></category>

		<guid isPermaLink="false">http://pocketjourney.wordpress.com/?p=16</guid>
		<description><![CDATA[Introduction NOTE: This tutorial was written for Android v1.0.  I have just updated the Android streaming media player tutorial/code to v1.5 (Cupcake) with some additional information on the updated code.  You should read that post as well as this one. This is a long tutorial, but for those of you that have been struggling with streaming of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=16&subd=pocketjourney&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p><strong><a href="http://pocketjourney.wordpress.com/wp-admin/None"></a>Introduction </strong></p>
<p><span style="color:#ff0000;"><span style="color:#000000;">NOTE: This tutorial was written for Android v1.0.  I have just updated the <a href="http://blog.pocketjourney.com/2009/12/27/android-map-tutorials-updated-to-v1-5-cupcake-mapview-mapactivity/">Android streaming media player tutorial/code to v1.5 (Cupcake)</a></span><span style="color:#000000;"> with some additional information on the updated code.  You should read that post </span></span><span style="color:#ff0000;"><span style="color:#000000;">as well as this one.</span></span></p>
<p>This is a long tutorial, but for those of you that have been struggling with streaming of .mp3 audio to Google&#8217;s Android&#8217;s MediaPlayer, then I hope this tutorial proves useful as you finalize your entries into <a title="Android Challenge" href="http://code.google.com/android/adc.html">Google&#8217;s Android Challenge</a></p>
<p>This tutorial will show how to roll your own streaming audio utility for <a title="Android's MediaPlayer" href="http://code.google.com/android/toolbox/apis/media.html">Android&#8217;s MediaPlayer</a>. We will buffer 10 seconds of audio and start playing that audio while the rest of the audio loads in the background. We store the streamed audio locally so you could cache it on device for later use or simply let it be garbage collected.</p>
<p>Here&#8217;s the <a title="Source Code" href="http://www.pocketjourney.com/downloads/pj/tutorials/tutorial3.zip">source code</a> for those that just want to jump in. You&#8217;ll also notice code for the other tutorials as I didn&#8217;t have time to strip them out.</p>
<p>Here are a few screenshots of what we&#8217;ll be creating:</p>
<p><img src="http://pocketjourney.files.wordpress.com/2008/04/tutorial-3-results-screenshots.gif?w=500" border="0" alt="Tutorial #3 results screenshots" /></p>
<p><span id="more-16"></span></p>
<p><strong>Basic Layout</strong></p>
<p>The tutorial consists of just two classes:</p>
<p style="padding-left:30px;"><strong>Tutorial3: </strong>Contains the UI layout and process button clicks<br />
<strong>StreamingMediaPlayer:</strong> Connects to the server, downloads audio into the buffer, and controls the functionality to ensure the audio continues to play seamlessly.</p>
<p>We&#8217;ll assume you know about UI layout using Android&#8217;s XML resource files and will instead jump right into the audio streaming code.</p>
<p><strong>Start Your Streaming</strong></p>
<p>Upon clicking the &#8220;Start Streaming&#8221; button, Tutorial3 creates an instance of StreamingMediaPlayer.</p>
<blockquote><p><em>new StreamingMediaPlayer(textStreamed, playButton, streamButton,progressBar);</em></p></blockquote>
<p>All UI elements are passed to StreamingMediaPlayer so it can perform UI update itself. In a more robust implementation, StreamingMediaPlayer would fire relevant update events and Tutorial3 would handle the UI updates. For simplicity &amp; cleaner code in this tutorial however, StreamingMediaPlayer will be directly updating the UI.</p>
<p>Tutorial3 then calls StreamingMediaPlayer.startStreaming():</p>
<p style="padding-left:30px;"><em>audioStreamer.startStreaming(&#8220;http://www.pocketjourney.com/audio.mp3&#8243;,1444, 180);</em></p>
<p>Three variables are passed to startStreaming(): a url for the media to stream (link to an .mp3 file in this tutorial), the length in kilobytes of the media file, and the lenght in seconds of the media file. These last two values will be used when updating the progress bar.</p>
<p>AudioStreamer.startStreaming() creates a new thread for streaming the content so we can immediately return control back to the user interface.</p>
<p style="padding-left:30px;"><em>public void startStreaming(final String mediaUrl, long mediaLengthInKb, long mediaLengthInSeconds) throws IOException {</em></p>
<p style="padding-left:60px;"><em>this.mediaLengthInKb = mediaLengthInKb;<br />
this.mediaLengthInSeconds = mediaLengthInSeconds;</em></p>
<p style="padding-left:60px;"><em>Runnable r = new Runnable() {</em></p>
<p style="padding-left:90px;"><em>public void run() { </em></p>
<p style="padding-left:120px;"><em>try { </em></p>
<p style="padding-left:150px;"><em>downloadAudioIncrement(mediaUrl);</em></p>
<p style="padding-left:120px;"><em>} catch (IOException e) {</em></p>
<p style="padding-left:150px;"><em>Log.e(getClass().getName(), &#8220;Initialization error for fileUrl=&#8221; + mediaUrl, e);<br />
return;</em></p>
<p style="padding-left:120px;"><em>} </em></p>
<p style="padding-left:90px;"><em>} </em></p>
<p style="padding-left:60px;"><em>};<br />
new Thread(r).start();</em></p>
<p style="padding-left:30px;"><em>}</em></p>
<p><strong>Incremental Media Download </strong></p>
<p>This is where the magic happens as we download media content from the the url stream until we have enough content buffered to start the MediaPlayer. We then let the MediaPlayer play in the background while we download the remaining audio. If the MediaPlayer reaches the end of the buffered audio, then we transfer any newly downloaded audio to the MediaPlayer and let it start playing again.</p>
<p>Things get a little tricky here because:</p>
<p style="padding-left:30px;"><em>(a) The MediaPlayer seems to lock the file so we can&#8217;t simply append our content to the existing file.<br />
(b) Pausing the MediaPlayer to load the new content takes awhile so we only want to interrupt it when absolutely necessary.<br />
(c) Accessing the MediaPlayer from a separate thread causes it to crash.</em></p>
<p>So with those caveats in mind, here&#8217;s the method that bufferes the media content to a temporary file:</p>
<p style="padding-left:30px;"><em>public void downloadAudioIncrement(String mediaUrl) throws IOException {</em></p>
<p style="padding-left:60px;"><em><span style="color:#008000;">// First establish connection to the media provider</span><br />
URLConnection cn = new URL(mediaUrl).openConnection();<br />
cn.connect();<br />
InputStream stream = cn.getInputStream();<br />
if (stream == null) {</em></p>
<p style="padding-left:90px;"><em>Log.e(getClass().getName(), &#8220;Unable to create InputStream for mediaUrl:&#8221; + mediaUrl);</em></p>
<p style="padding-left:60px;"><em>}</em></p>
<p style="padding-left:60px;"><em><span style="color:#008000;">// Create the temporary file for buffering data into</span><br />
downloadingMediaFile = File.createTempFile(&#8220;downloadingMedia&#8221;, &#8220;.dat&#8221;);<br />
FileOutputStream out = new FileOutputStream(downloadingMediaFile);</em></p>
<p style="padding-left:60px;"><em><span style="color:#008000;">// Start reading data from the URL stream<br />
</span>byte buf[] = new byte[16384];<br />
int totalBytesRead = 0, incrementalBytesRead = 0;<br />
do {</em></p>
<p style="padding-left:90px;"><em>int numread = stream.read(buf);<br />
if (numread &lt;= 0) {</em></p>
<p style="padding-left:120px;"><em><span style="color:#008000;">// Nothing left to read so quit</span><br />
break; </em></p>
<p style="padding-left:90px;"><em>} else {</em></p>
<p style="padding-left:120px;"><em>out.write(buf, 0, numread);<br />
totalBytesRead += numread;<br />
incrementalBytesRead += numread;<br />
totalKbRead = totalBytesRead/1000;</em></p>
<p style="padding-left:120px;"><span style="color:#008000;">// Test whether we need to transfer buffered data to the MediaPlayer</span><br />
testMediaBuffer();<br />
<span style="color:#008000;"><br />
// Update the status for ProgressBar and TextFields<br />
</span>fireDataLoadUpdate();</p>
<p style="padding-left:90px;"><em>}</em></p>
<p style="padding-left:60px;"><em>} while (true); </em></p>
<p style="padding-left:60px;"><em><span style="color:#008000;">// Lastly transfer fully loaded audio to the MediaPlayer and close the InputStream</span><br />
fireDataFullyLoaded();<br />
<em>stream.close();</em></em></p>
<p style="padding-left:30px;"><em>}</em></p>
<p><strong>What&#8217;s up with testMediaBuffer()?</strong></p>
<p>So if you were paying attention, an important piece of functionality must reside in the testMediaBuffer() method. You&#8217;re right. That&#8217;s the method where we determine whether we need to transfer buffered data to the MediaPlayer because we have enough to start the MediaPlayer or because the MediaPlayer has already played out its previous buffer content.</p>
<p><span style="color:#ff0000;">Before we jump into that, please take note that interacting with a MediaPlayer on non-main UI thread can cause crashes so we always ensure we are interacting with the UI on the main-UI Thread by using a Handler when necessary. For example, we must do so in the following method because it is being called by the media streaming Thread.</span></p>
<p style="padding-left:30px;"><em>private void testMediaBuffer() {</em></p>
<p style="padding-left:60px;"><em><span style="color:#008000;">// We&#8217;ll place our following code into a Runnable so the Handler can call it for running<br />
// on the main UI thread</span><br />
Runnable updater = new Runnable() {</em></p>
<p style="padding-left:90px;"><em>public void run() {</em></p>
<p style="padding-left:120px;"><em>if (mediaPlayer == null) {</em></p>
<p style="padding-left:150px;"><em><span style="color:#008000;">// The MediaPlayer has not yet been created so see if we have<br />
// the minimum buffered data yet.<br />
// For our purposes, we take the minimum buffered requirement to be:<br />
// INTIAL_KB_BUFFER = 96*10/8;//assume 96kbps*10secs/8bits per byte</span><br />
if ( totalKbRead &gt;= INTIAL_KB_BUFFER) {</em></p>
<p style="padding-left:180px;"><em>try {</em></p>
<p style="padding-left:210px;"><em><span style="color:#008000;">// We have enough buffered content so start the MediaPlayer</span><br />
startMediaPlayer(bufferedFile);</em></p>
<p style="padding-left:180px;"><em>} catch (Exception e) {</em></p>
<p style="padding-left:210px;"><em>Log.e(getClass().getName(), &#8220;Error copying buffered conent.&#8221;, e);</em></p>
<p style="padding-left:180px;"><em>}</em></p>
<p style="padding-left:150px;"><em>}</em></p>
<p style="padding-left:120px;"><em>} else if ( mediaPlayer.getDuration() &#8211; mediaPlayer.getCurrentPosition() &lt;= 1000 ){</em></p>
<p style="padding-left:150px;"><em><span style="color:#008000;">// The MediaPlayer has been started and has reached the end of its buffered<br />
// content. We test for &lt; 1second of data (i.e. 1000ms) because the media<br />
// player will often stop when there are still a few milliseconds of data left to play</span><br />
transferBufferToMediaPlayer();</em></p>
<p style="padding-left:120px;"><em>}</em></p>
<p style="padding-left:90px;"><em>}</em></p>
<p style="padding-left:60px;"><em>};<br />
handler.post(updater);</em></p>
<p style="padding-left:30px;"><em>}</em></p>
<p><strong>Starting the MediaPlayer with Initial Content Buffer</strong></p>
<p>Starting the MediaPlayer is very straightforward now. We simply copy all the currently buffered content<br />
into a new Ffile and start the MediaPlayer with it.</p>
<p style="padding-left:30px;"><em>private void startMediaPlayer(File bufferedFile) {</em></p>
<p style="padding-left:60px;"><em>try {</em></p>
<p style="padding-left:90px;"><em>File bufferedFile = File.createTempFile(&#8220;playingMedia&#8221;, &#8220;.dat&#8221;);<br />
FileUtils.copyFile(downloadingMediaFile,bufferedFile);</em><em>} catch (IOException e) {</em></p>
<p style="padding-left:90px;">mediaPlayer = new MediaPlayer();<br />
mediaPlayer.setDataSource(bufferedFile.getAbsolutePath());<br />
mediaPlayer.prepare();<br />
fireDataPreloadComplete();</p>
<p style="padding-left:60px;">
<p style="padding-left:90px;"><em>Log.e(getClass().getName(), &#8220;Error initializing the MediaPlaer.&#8221;, e);<br />
return;</em></p>
<p style="padding-left:60px;"><em>}</em></p>
<p style="padding-left:30px;"><em>}</em></p>
<p><strong>Transferring Buffered Content to a MediaPlayer That is Already Playing</strong></p>
<p>This is a little trickier but not much. We simply pause the MediaPlayer if it was playing (i.e. the user had not pressed pause), copy over the currently downloaded media content (which may be all of it by now) and then restart the MediaPlayer if it was previously running or had hit the end of its buffer due to a slow network.</p>
<p style="padding-left:30px;"><em>private void transferBufferToMediaPlayer() {</em></p>
<p style="padding-left:60px;"><em>try {</em></p>
<p style="padding-left:90px;"><em><span style="color:#008000;">// Determine if we need to restart the player after transferring data (e.g. perhaps the user<br />
// pressed pause) &amp; also store the current audio position so we can reset it later. </span><br />
boolean wasPlaying = mediaPlayer.isPlaying();<br />
int curPosition = mediaPlayer.getCurrentPosition();<br />
mediaPlayer.pause();</em></p>
<p style="padding-left:90px;"><em><span style="color:#008000;">// Copy the current buffer file as we can&#8217;t download content into the same file that<br />
// the MediaPlayer is reading from.</span><br />
File bufferedFile = File.createTempFile(&#8220;playingMedia&#8221;, &#8220;.dat&#8221;);<br />
FileUtils.copyFile(downloadingMediaFile,bufferedFile);</em></p>
<p style="padding-left:90px;"><em><span style="color:#008000;">// Create a new MediaPlayer. We&#8217;ve tried reusing them but that seems to result in<br />
// more system crashes than simply creating new ones.</span><br />
mediaPlayer = new MediaPlayer();<br />
mediaPlayer.setDataSource(bufferedFile.getAbsolutePath());<br />
mediaPlayer.prepare();<br />
mediaPlayer.seekTo(curPosition);</em></p>
<p style="padding-left:90px;"><em><span style="color:#008000;">// Restart if at end of prior beuffered content or mediaPlayer was previously playing.<br />
// NOTE: We test for &lt; 1second of data because the media player can stop when there is still<br />
// a few milliseconds of data left to play</span><br />
boolean atEndOfFile = mediaPlayer.getDuration() &#8211; mediaPlayer.getCurrentPosition() &lt;= 1000;<br />
if (wasPlaying || atEndOfFile){</em></p>
<p style="padding-left:120px;"><em>mediaPlayer.start();</em></p>
<p style="padding-left:90px;"><em>}</em></p>
<p style="padding-left:60px;"><em>}catch (Exception e) {</em></p>
<p style="padding-left:90px;"><em>Log.e(getClass().getName(), &#8220;Error updating to newly loaded content.&#8221;, e);</em></p>
<p style="padding-left:60px;"><em>}</em></p>
<p style="padding-left:30px;"><em>}</em></p>
<p><strong>Conclusion</strong></p>
<p>To get the real feel for how your audio will download, make sure to set it to a slower network speed. I recommend setting to AT&amp;T&#8217;s EDGE network setting as it should give a lower limit on expected performance. You can make these setting&#8217;s easy in Eclipse by setting going into your Run or Debug setting&#8217;s dialog and making these selections.</p>
<p style="text-align:center;"><img class="size-full wp-image-19" src="http://pocketjourney.files.wordpress.com/2008/04/edge-settings-in-eclipse.gif?w=378&#038;h=237" alt="EDGE settings in Eclipse" width="378" height="237" /></p>
<p><a href="http://pocketjourney.wordpress.com/wp-admin/None"></a></p>
<p>Well that&#8217;s it. I&#8217;ve inluded additional code for handling the ProgressBar and TextField updates but that should all be sufficiently easy to understand once you understand the rest of the code. Good luck during the next week as you finish your <a title="Android Challenge" href="http://code.google.com/android/adc.html">Android Challenge</a> submissions.</p>
<p>And of course, here&#8217;s the <a title="Source Code" href="http://www.pocketjourney.com/downloads/pj/tutorials/tutorials_1.5.zip">source code</a>. Please post a comment below if I need to explain anything in more detail. You&#8217;ll also notice code for the other tutorials as I didn&#8217;t have time to strip them out.</p>
<p><strong>Other Tutorials</strong></p>
<p><a title="Transparent Panel (Linear Layout) On MapView (Google Map)" rel="bookmark" href="http://blog.pocketjourney.com/2008/03/15/tutorial-1-transparent-panel-linear-layout-on-mapview-google-map/">Tutorial 1: Transparent Panel (Linear Layout) On MapView (Google Map)</a><br />
<a title="Transparent Panel (Linear Layout) On MapView (Google Map)" rel="bookmark" href="http://blog.pocketjourney.com/2008/03/15/tutorial-1-transparent-panel-linear-layout-on-mapview-google-map/">Tutorial 2: </a><a title="“Hit” testing on a View (MapView)" rel="bookmark" href="http://blog.pocketjourney.com/2008/03/19/tutorial-2-mapview-google-map-hit-testing-for-display-of-popup-windows/">“Hit” testing on a View (MapView)</a><br />
<a href="http://blog.pocketjourney.com/2008/04/30/android-tutorial-image-text-only-buttons">Tutorial 4.1: Image and Text-Only Buttons</a> <a title="Custom Media Streaming with MediaPlayer" rel="bookmark" href="http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/"><br />
</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pocketjourney.wordpress.com/16/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pocketjourney.wordpress.com/16/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pocketjourney.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pocketjourney.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pocketjourney.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pocketjourney.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pocketjourney.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pocketjourney.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pocketjourney.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pocketjourney.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pocketjourney.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pocketjourney.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.pocketjourney.com&blog=3166094&post=16&subd=pocketjourney&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/feed/</wfw:commentRss>
		<slash:comments>206</slash:comments>
<enclosure url="http://www.pocketjourney.com/audio.mp3" length="1444676" type="audio/x-mpeg" />
	
		<media:content url="http://1.gravatar.com/avatar/9d07abb76faa58b0d506b3fa5bc03804?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Biosopher</media:title>
		</media:content>

		<media:content url="http://pocketjourney.files.wordpress.com/2008/04/tutorial-3-results-screenshots.gif" medium="image">
			<media:title type="html">Tutorial #3 results screenshots</media:title>
		</media:content>

		<media:content url="http://pocketjourney.files.wordpress.com/2008/04/edge-settings-in-eclipse.gif" medium="image">
			<media:title type="html">EDGE settings in Eclipse</media:title>
		</media:content>
	</item>
	</channel>
</rss>