<?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>iPhone Tutorial &#124; iPhone iOS4 iPad SDK Development &#38; Programming Blog &#187; Display WebPage and AudioFile Play</title>
	<atom:link href="http://www.edumobile.org/iphone/tag/display-webpage-and-audiofile-play/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.edumobile.org/iphone</link>
	<description></description>
	<lastBuildDate>Tue, 07 Feb 2012 11:17:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Display WebPage and AudioFile play in TabBar Application</title>
		<link>http://www.edumobile.org/iphone/ipad-development/display-webpage-and-audiofile-play-in-tabbar-application/</link>
		<comments>http://www.edumobile.org/iphone/ipad-development/display-webpage-and-audiofile-play-in-tabbar-application/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 10:17:58 +0000</pubDate>
		<dc:creator>Sushant</dc:creator>
				<category><![CDATA[iPad Development]]></category>
		<category><![CDATA[Display WebPage and AudioFile Play]]></category>
		<category><![CDATA[Display WebPage and AudioFile play in TabBar Application]]></category>
		<category><![CDATA[iphone tutorials]]></category>

		<guid isPermaLink="false">http://www.edumobile.org/iphone/?p=2497</guid>
		<description><![CDATA[This is the TabBar application. In this application we will see how to display Web page and play audio file in the iPad. We will create this application using TabBar Application Template.]]></description>
			<content:encoded><![CDATA[<p>This is the TabBar application. In this application we will see how to display Web page and play audio file in the iPad. We will create this application using TabBar Application Template.</p>
<p><strong>Step 1:</strong> Create a TabBar application using template. Give the application name &#8220;Tabbar_Videoplay_iPad&#8221;.</p>
<p><strong>Step 2</strong>: code automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.</p>
<p><strong>Step 3:</strong> Xpand classes and notice Interface Builder created the FirstViewController class for you. Expand Resources and notice the template generated a separate  nib,FirstViewr.xib, for the “ Tabbar_Videoplay_iPad”.</p>
<p><strong>Step 4:</strong> We need to add UIViewController class in the project . Select classes -> Add -> New Files -> Select UIViewController class and give the class name &#8220;AudioPlayViewController&#8221;. Select corresponding .xib file and targeted for iPad.</p>
<p><strong>Step 5: </strong>We have added AudioToolbox and AVFoundation framework in the Frameworks folder.</p>
<p><strong>Step 6:</strong> We need to add two music file in the resource folder. Give the name of the music file &#8220;sound.aif&#8221;,&#8221;music.mp3&#8243;.</p>
<p><strong>Step 7:</strong> In the FirstViewController.h file we have created instance of UIWebView class . So make the following changes in the file.</p>
<div class="codesnip-container" >
<div class="objc codesnip" style="font-family:monospace;"><span class="co1">#import &lt;UIKit/UIKit.h&gt;</span></p>
<p><span class="kw1">@interface</span> FirstViewController <span class="sy0">:</span> UIViewController <span class="br0">&#123;</span><br />
&nbsp; IBOutlet UIWebView <span class="sy0">*</span>webDisplay;<br />
<span class="br0">&#125;</span><br />
<span class="kw1">@property</span><span class="br0">&#40;</span>nonatomic,retain<span class="br0">&#41;</span> UIWebView <span class="sy0">*</span>webDisplay;</div>
</div>
<p><strong>Step 8: </strong>Double click the MainWindow.xib file and open it to the Interface Builder. Select the FirstViewController from the TabBar Controller and bring up Attribute Inspector and delete the NIB name (See the figure 1). Now drag the WebView from the library and place it to the view window (See the figure 2). Select the first tab from the view window and bring up Connection Inspector and connect webDisplay to the Web View (See the figure 3). Save the MainWindow.xib file and close it and go back to the Xcode.<br />
<a href="http://www.edumobile.org/iphone/wp-content/uploads/2010/07/1-77.jpg"><img src="http://www.edumobile.org/iphone/wp-content/uploads/2010/07/1-77-300x215.jpg" alt="" title="1-7" width="300" height="215" class="alignnone size-medium wp-image-2565" /></a></p>
<p>               <strong>Figure 1</strong></p>
<p><a href="http://www.edumobile.org/iphone/wp-content/uploads/2010/07/2-42.jpg"><img src="http://www.edumobile.org/iphone/wp-content/uploads/2010/07/2-42-300x225.jpg" alt="" title="2-4" width="300" height="225" class="alignnone size-medium wp-image-2566" /></a></p>
<p>                  <strong>Figure 2</strong></p>
<p><a href="http://www.edumobile.org/iphone/wp-content/uploads/2010/07/3-1.jpg"><img src="http://www.edumobile.org/iphone/wp-content/uploads/2010/07/3-1-300x215.jpg" alt="" title="3-1" width="300" height="215" class="alignnone size-medium wp-image-2567" /></a></p>
<p>                 <strong>Figure 3</strong></p>
<p><strong>Step 9: </strong>Open the FirstViewController.m file and make the following changes in the file.</p>
<div class="codesnip-container" >
<div class="objc codesnip" style="font-family:monospace;"><span class="sy0">-</span> <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span>viewDidLoad <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span class="kw5">NSString</span></a> <span class="sy0">*</span>urlAddress <span class="sy0">=</span> <span class="co3">@</span><span class="st0">&quot;http://www.google.com&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/"><span class="kw5">NSURL</span></a> <span class="sy0">*</span>url <span class="sy0">=</span> <span class="br0">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/"><span class="kw5">NSURL</span></a> URLWithString<span class="sy0">:</span>urlAddress<span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/"><span class="kw5">NSURLRequest</span></a> <span class="sy0">*</span>requestObj <span class="sy0">=</span> <span class="br0">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/"><span class="kw5">NSURLRequest</span></a> requestWithURL<span class="sy0">:</span>url<span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>webDisplay loadRequest<span class="sy0">:</span>requestObj<span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="br0">&#91;</span>super viewDidLoad<span class="br0">&#93;</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p><strong>Step 10: </strong>In the AudioPlayViewController.h file , we have import AudioToolbox and AVFoundation framework. Create an instance of  AVAudioPlayer and UIButton class. Define two IBAction method. So make the following changes in the file.</p>
<div class="codesnip-container" >
<div class="objc codesnip" style="font-family:monospace;"><span class="co1">#import &lt;UIKit/UIKit.h&gt;</span><br />
<span class="co1">#import &lt;AudioToolbox/AudioToolbox.h&gt;</span><br />
<span class="co1">#import &lt;AVFoundation/AVFoundation.h&gt;</span></p>
<p><span class="kw1">@interface</span> AudioPlayViewController <span class="sy0">:</span> UIViewController &nbsp;&lt;AVAudioPlayerDelegate&gt; <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; SystemSoundID systemSoundID;<br />
&nbsp; &nbsp; &nbsp; &nbsp; AVAudioPlayer <span class="sy0">*</span>player;<br />
&nbsp; &nbsp; &nbsp; &nbsp; UIButton <span class="sy0">*</span>StartStopSound;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span class="br0">&#125;</span></p>
<p><span class="kw1">@property</span> <span class="br0">&#40;</span>nonatomic, retain<span class="br0">&#41;</span> IBOutlet AVAudioPlayer <span class="sy0">*</span>player;<br />
<span class="kw1">@property</span> <span class="br0">&#40;</span>nonatomic, retain<span class="br0">&#41;</span> IBOutlet UIButton <span class="sy0">*</span>StartStopSound;</p>
<p>
<span class="sy0">-</span> <span class="br0">&#40;</span>IBAction<span class="br0">&#41;</span> playSound<span class="sy0">:</span> <span class="br0">&#40;</span><span class="kw4">id</span><span class="br0">&#41;</span> sender;<br />
<span class="sy0">-</span> <span class="br0">&#40;</span>IBAction<span class="br0">&#41;</span> playSong<span class="sy0">:</span> <span class="br0">&#40;</span><span class="kw4">id</span><span class="br0">&#41;</span> sender;</div>
</div>
<p><strong>Step 11: </strong>Double click the AudioPlayViewController.xib file and open it to the view window. First drag the two Round Rect from the library and place it to the view window and give the name &#8220;Play Sound&#8221; , &#8220;Play Song&#8221;. Select the  &#8221;Play Sound&#8221; button and bring up connection Inspector and drag Touch Up Inside to the File Owner icon select playSound: action. Do the same thing for the &#8220;Play Song&#8221;  button and select the playSong: action. Connect File&#8217;s Owner icon to the &#8220;Play Song&#8221; button and select StartStopSound. Now save the AudioPlayViewController.xib file, close it and go back to the Xcode.</p>
<p><strong>Step 12:</strong> Open the AudioPlayViewController.m file and make the following changes:</p>
<div class="codesnip-container" >
<div class="objc codesnip" style="font-family:monospace;"><span class="sy0">-</span> <span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span>viewDidLoad <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; NSLog<span class="br0">&#40;</span><span class="co3">@</span><span class="st0">&quot;InView did load&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; AudioServicesCreateSystemSoundID<span class="br0">&#40;</span><span class="br0">&#40;</span>CFURLRef<span class="br0">&#41;</span><span class="br0">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/"><span class="kw5">NSURL</span></a> fileURLWithPath<span class="sy0">:</span><span class="br0">&#91;</span><span class="br0">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/"><span class="kw5">NSBundle</span></a> mainBundle<span class="br0">&#93;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pathForResource<span class="sy0">:</span> <span class="co3">@</span><span class="st0">&quot;sound&quot;</span> ofType<span class="sy0">:</span><span class="co3">@</span><span class="st0">&quot;aif&quot;</span><span class="br0">&#93;</span><span class="br0">&#93;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sy0">&amp;</span>systemSoundID<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; player <span class="sy0">=</span> <span class="br0">&#91;</span><span class="br0">&#91;</span>AVAudioPlayer alloc<span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initWithContentsOfURL<span class="sy0">:</span><span class="br0">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/"><span class="kw5">NSURL</span></a> fileURLWithPath<span class="sy0">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#91;</span><span class="br0">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/"><span class="kw5">NSBundle</span></a> mainBundle<span class="br0">&#93;</span> pathForResource<span class="sy0">:</span><span class="co3">@</span><span class="st0">&quot;music&quot;</span> ofType<span class="sy0">:</span><span class="co3">@</span><span class="st0">&quot;mp3&quot;</span><span class="br0">&#93;</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error<span class="sy0">:</span><span class="kw2">nil</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>player prepareToPlay<span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span class="br0">&#125;</span></p>
<p>
<span class="sy0">-</span><span class="br0">&#40;</span>IBAction<span class="br0">&#41;</span> playSound<span class="sy0">:</span><span class="br0">&#40;</span><span class="kw4">id</span><span class="br0">&#41;</span> sender <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; NSLog<span class="br0">&#40;</span><span class="co3">@</span><span class="st0">&quot;In Sample&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; AudioServicesPlaySystemSound<span class="br0">&#40;</span>systemSoundID<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="sy0">-</span><span class="br0">&#40;</span>IBAction<span class="br0">&#41;</span> playSong<span class="sy0">:</span><span class="br0">&#40;</span><span class="kw4">id</span><span class="br0">&#41;</span> sender <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="br0">&#91;</span><span class="br0">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span class="kw5">NSString</span></a> stringWithFormat<span class="sy0">:</span><span class="co3">@</span><span class="st0">&quot;%@&quot;</span>, <span class="br0">&#91;</span>StartStopSound titleForState<span class="sy0">:</span>UIControlStateNormal<span class="br0">&#93;</span><span class="br0">&#93;</span> isEqualToString<span class="sy0">:</span><span class="co3">@</span><span class="st0">&quot;Play Song&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>player play<span class="br0">&#93;</span>;&nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>StartStopSound setTitle<span class="sy0">:</span><span class="co3">@</span><span class="st0">&quot;Stop Song&quot;</span> forState<span class="sy0">:</span>UIControlStateNormal<span class="br0">&#93;</span>; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span> <span class="br0">&#123;</span>&nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>player stop<span class="br0">&#93;</span>;&nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>StartStopSound setTitle<span class="sy0">:</span><span class="co3">@</span><span class="st0">&quot;Play Song&quot;</span> forState<span class="sy0">:</span>UIControlStateNormal<span class="br0">&#93;</span>; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> &nbsp; &nbsp; &nbsp; <br />
<span class="br0">&#125;</span></div>
</div>
<p><strong>Step 13:</strong> Double click the MainWindow.xib file and open it to the Interface Builder. Select the ViewController from the TabBar Controller  in MainWindow and bring up Identity Inspector and change the class name into AudioPlayViewController and bring up Attribute Inspector, set the NIB name into &#8220;AudioPlayViewController&#8221;. Now save the MainWindow.xib file, close it and go back to the Xcode.</p>
<p><strong>Step 14: </strong>Now Compile the application and run it in the Simulator.</p>
<p><a href="http://www.edumobile.org/iphone/wp-content/uploads/2010/07/1-74.jpg"><img class="alignnone size-medium wp-image-2498" title="1-7" src="http://www.edumobile.org/iphone/wp-content/uploads/2010/07/1-74-234x300.jpg" alt="" width="234" height="300" /></a></p>
<p>You can <strong>Download SourceCode</strong> from here <a href="http://www.edumobile.org/iphone/wp-content/uploads/2010/07/Tabbar_Videoplay_iPad.zip">Tabbar_Videoplay_iPad</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.edumobile.org/iphone/ipad-development/display-webpage-and-audiofile-play-in-tabbar-application/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

