<?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>MediaPlayer Archives - Creatronix</title>
	<atom:link href="https://creatronix.de/tag/mediaplayer/feed/" rel="self" type="application/rss+xml" />
	<link>https://creatronix.de/tag/mediaplayer/</link>
	<description>My adventures in code &#38; business</description>
	<lastBuildDate>Sun, 16 Oct 2022 07:09:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>My first iPhone App</title>
		<link>https://creatronix.de/my-first-iphone-app/</link>
		
		<dc:creator><![CDATA[Jörn]]></dc:creator>
		<pubDate>Sat, 04 Mar 2017 20:29:49 +0000</pubDate>
				<category><![CDATA[Android & iOS development]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[MediaPlayer]]></category>
		<category><![CDATA[Xcode]]></category>
		<guid isPermaLink="false">http://creatronix.de/?p=521</guid>

					<description><![CDATA[<p>After carrying around my iPhone 6 for two and a half years I finally wanted to know how to build an iOS app. Getting started I used this tutorial from apple and rolled with the punches: Installing XCode takes ages!  Download 4,6 GB 🙁 First issue: when accidentally making the wrong connection between a UI-Element&#8230;</p>
<p>The post <a href="https://creatronix.de/my-first-iphone-app/">My first iPhone App</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>After carrying around my iPhone 6 for two and a half years I finally wanted to know how to build an iOS app.</p>
<h2>Getting started</h2>
<p>I used <a href="https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/">this tutorial from apple</a> and rolled with the punches:</p>
<h3>Installing XCode</h3>
<p>takes ages!  Download 4,6 GB 🙁</p>
<p>First issue: when accidentally making the wrong connection between a UI-Element and the ViewController (@IBOutlet instead of @IBAction) You have to remove the connection in the code _and_ in the storyboard via context menu.</p>
<h2>First own app</h2>
<p>After I was done with the tutorial I wrote an app I always wanted to write:</p>
<p>A music player app to make learning songs easy. Use case: You want to learn a solo from e.g. Metallica&#8217;s &#8220;Nothing else matters&#8221; and You want to play along the music.</p>
<p>Requirements so far:</p>
<p><span id="more-521"></span></p>
<ul>
<li>Browse and play songs from music library</li>
<li>Set marker at the beginning of a section you want to practice</li>
<li>Possibility to rename the button to a meaningful name e.g. Solo, Chorus</li>
<li>Select play time via a scrub slider</li>
</ul>
<h3>Access media library on device</h3>
<p>To access the music library the user has to acknowledge the access.  An app that uses the music library has to add <code>NSAppleMusicUsageDescription</code> to the plist file. To get all the items from your music library is pretty straight forward then:</p>
<pre>import MediaPlayer

let mediaItems = MPMediaQuery.songs().items</pre>
<p>Here You can see the first view, a table list of all songs:<br />
<a href="https://creatronix.de/wp-content/uploads/2017/03/img_4005.jpg"><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-597" src="https://creatronix.de/wp-content/uploads/2017/03/img_4005.jpg" alt="" width="640" height="1136" srcset="https://creatronix.de/wp-content/uploads/2017/03/img_4005.jpg 640w, https://creatronix.de/wp-content/uploads/2017/03/img_4005-169x300.jpg 169w, https://creatronix.de/wp-content/uploads/2017/03/img_4005-577x1024.jpg 577w" sizes="(max-width: 640px) 100vw, 640px" /></a></p>
<h3>Add an audioplayer</h3>
<p>is pretty straight forward:</p>
<pre>do {
    myAudioPlayer = try AVAudioPlayer(contentsOf: url!)
    myAudioPlayer.prepareToPlay()
    myAudioPlayer.volume = 1.0
} catch  {
    print(error)
}</pre>
<p>Add play and pause button</p>
<p>[x] add slider for selecting track time</p>
<p>[x] round the corners of a button</p>
<pre class="default prettyprint prettyprinted"><code><span class="pln">button</span><span class="pun">.</span><span class="pln">layer</span><span class="pun">.</span><span class="pln">cornerRadius </span><span class="pun">=</span> <span class="lit">5</span></code></pre>
<p>[x] add a popup view to show when marker is set</p>
<p>[x] Convert TimeInterval to hours, mins seconds</p>
<pre>func stringFromTimeInterval(interval: TimeInterval) -&gt; String {
    let ti = NSInteger(interval)
    
    let tenth = Int((interval.truncatingRemainder(dividingBy: 1.0)) * 1000) / 100
    let seconds = ti % 60
    let minutes = (ti / 60) % 60
    let hours = (ti / 3600)
    
    return String(format: "%0.1d:%0.2d:%0.2d.%0.1d", hours, minutes, seconds, tenth)
}</pre>
<p><a href="https://creatronix.de/wp-content/uploads/2017/03/img_4006.jpg"><img decoding="async" class="alignnone size-full wp-image-598" src="https://creatronix.de/wp-content/uploads/2017/03/img_4006.jpg" alt="" width="640" height="1136" srcset="https://creatronix.de/wp-content/uploads/2017/03/img_4006.jpg 640w, https://creatronix.de/wp-content/uploads/2017/03/img_4006-169x300.jpg 169w, https://creatronix.de/wp-content/uploads/2017/03/img_4006-577x1024.jpg 577w" sizes="(max-width: 640px) 100vw, 640px" /></a></p>
<h3>Deploying the app to your own device</h3>
<p>Although the xcode simulator is nice you cannot access music from within the simulator so getting the app to work on a real device is mandatory early on.</p>
<p><strong>There is the myth that you have to be a paying member of the apple developer program to test your app on your own phone. That&#8217;s wrong!</strong></p>
<p>Anyway you need an account if You want to publish the app in the app store.</p>
<ol>
<li>Open Xode preferences (Xcode &gt; Preferences…)</li>
<li>Click the ‘Accounts’ tab</li>
<li>Login with your Apple ID (+ &gt; Add Apple ID…)</li>
<li>Project Editor -&gt; Signing -&gt; Team -&gt; &lt;User&gt;</li>
<li>On iPhone: Settings -&gt; General -&gt; Device Management -&gt; Trust Developer</li>
</ol>
<p>After that You can deploy and test the app on your phone or tablet.</p>
<h2>Beta-Test of the App</h2>
<p>After I&#8217;ve implemented the basic use cases I showed the app to some colleagues. And got a bunch of new requirements and tips for improvements.</p>
<ul>
<li>Instead to the slider show a waveform to make identifying the section easier</li>
<li>Set marker for start and end to replay the loop</li>
<li>Persist already set markers</li>
<li>Mark tracks which already have markers</li>
<li>Start and stop playing via Siri</li>
</ul>
<p>My colleagues found a couple of bugs as well:</p>
<ul>
<li>when selecting a track which is not on your device at the moment, the app crashes</li>
<li>the layout is not suitable for landscape orientation</li>
</ul>
<p>Stay tuned for the second part!</p>
<p>The post <a href="https://creatronix.de/my-first-iphone-app/">My first iPhone App</a> appeared first on <a href="https://creatronix.de">Creatronix</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
