Learn to Code While Building Apps - The Complete iOS Development Bootcamp

Overview

App Brewery Banner

Xylophone

Our Goal

The goal of this tutorial is to dive into a simple iOS recipe - how to play sound and use an Apple library called AVFoundation. The most important skill of a great programmer is being able to solve your own problems. We’ll do that by exploring StackOverflow, Apple Documentation and learning how to search for solutions effectively. By learning to use these tools, you’ll be able to start adding custom features to an app and get it to do what you want it to.

What you will create

You will be making your first musical instrument! Music apps are so popular on the App Store that they even get their own category. So in this module, we’re going to make a colourful XyloPhone app. Get it? Ok, the jokes are bad, but remember, I only wrote the good ones...

What you will learn

  • How to play sound using AVFoundation and AVAudioPlayer.
  • Understand Apple documentation and how to use StackOverflow.
  • Functions and methods in Swift.
  • Data types.
  • Swift loops.
  • Variable scope.
  • The ViewController lifecycle.
  • Error handling in Swift.
  • Code refactoring.
  • Basic debugging.

Replacement Code

import UIKit
import AVFoundation

class ViewController: UIViewController {
    
    var player: AVAudioPlayer!

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBAction func keyPressed(_ sender: UIButton) {
        playSound()
    }
    
    func playSound() {
        let url = Bundle.main.url(forResource: "C", withExtension: "wav")
        player = try! AVAudioPlayer(contentsOf: url!)
        player.play()
                
    }
}

This is a companion project to The App Brewery's Complete App Development Bootcamp, check out the full course at www.appbrewery.co

End Banner

You might also like...
Soundable is a tiny library that uses AVFoundation to manage the playing of sounds in iOS applications in a simple and easy way

Soundable is a tiny library that uses AVFoundation to manage the playing of sounds in iOS applications in a simple and easy way. You can play

Swift audio synthesis, processing, & analysis platform for iOS, macOS and tvOS
Swift audio synthesis, processing, & analysis platform for iOS, macOS and tvOS

AudioKit AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS (including Catalyst), and tvOS. Installation To add AudioKit

AudioKit Synth One: Open-Source iOS Synthesizer App
AudioKit Synth One: Open-Source iOS Synthesizer App

AudioKit Synth One We've open-sourced the code for this synthesizer so that everyone is able to make changes to the code, introduce new features, fix

Classical music front-end for Apple Music: iOS app

concertino_ios Concertino is a classical music front-end for Apple Music. It's splitted in several projects. This one provides only the iOS app. (Ther

iOS application for finding formants in spoken sounds
iOS application for finding formants in spoken sounds

FORMANT PLOTTER Buy on the App Store: https://itunes.apple.com/us/app/formant-analyzer/id799183655?mt=8&uo=4&at=11l6hc&ct=fnd This is an iOS project t

:musical_keyboard: A simple iOS synthesiser powered by Pure Data. Based on the Korg Monotron Delay.

Monotone Delay A simple iOS Synthesizer based on Pure Data. You can see a short demo of the app on youtube. If you want to buy the app you can find it

Music Player for iOS which looks & feels like classic player
Music Player for iOS which looks & feels like classic player

Prodigal Music Player APP looks and feels like a classic device. Bring back the good old player to life. Screenshots Home Page Album Gallery Home Page

Voice Memos is an audio recorder App for iPhone and iPad that covers some of the new technologies and APIs introduced in iOS 8 written in Swift.
Voice Memos is an audio recorder App for iPhone and iPad that covers some of the new technologies and APIs introduced in iOS 8 written in Swift.

VoiceMemos Voice Memos is a voice recorder App for iPhone and iPad that covers some of the new technologies and APIs introduced in iOS 8 written in Sw

iOS music player app that downloads music from the internet, even YouTube
iOS music player app that downloads music from the internet, even YouTube

About YouTag is an iOS music player app that downloads music from the internet, even YouTube, and manages it in a local library. Music videos can also

Owner
The App Brewery
The Best Programming School in the World
The App Brewery
Sample project displaying bugs in the StarSDK while using Kotlin Native

StarSampleSdk iOS Bugs that need to be reproduced Retrieving network printer status fails after subsequent attempts Star Bluetooth printer with an act

Bailey Pollard 1 Aug 18, 2022
Contains common infrastructural code for apps to communicate among computers, sound synthesizers, and other multimedia devices via OSC.

The CoreOSC package contains common infrastructural code for your apps to communicate among computers, sound synthesizers, and other multimedia devices via OSC.

Sammy Smallman 3 Oct 7, 2022
Fast Campus iOS App Development All-in-one Package Online Clone Coding

애플뮤직 클론 코딩 패스트캠퍼스 iOS 앱 개발 올인원 패키지 Online 클론코딩 사용요소 UICollectionReusableView , c

JungMin 1 Dec 21, 2021
AudioPlayer is a simple class for playing audio in iOS, macOS and tvOS apps.

AudioPlayer AudioPlayer is a simple class for playing audio in iOS, macOS and tvOS apps.

Tom Baranes 260 Nov 27, 2022
Run iOS apps & games on M1 Mac with mouse, keyboard and controller support.

‎ PlayCover Run iOS apps & games on M1 Mac with mouse, keyboard and controller support. Showcase · Contribute · Discord About the fork & Disclaimer Th

Derek Jones 10 Aug 25, 2022
OSCKit - The OSCKit package provides the classes needed for your apps to communicate among computers, sound synthesizers

OSCKit The OSCKit package provides the classes needed for your apps to communica

Sammy Smallman 23 Nov 27, 2022
MusicalInstrument - Play musical instrument in just few lines of swift code

MusicalInstrument Play musical instrument in just few lines of swift code. Requi

null 2 Feb 3, 2022
Background sounds feature from iOS 15 on iOS 11+

Tranquil Background sounds feature from iOS 15 on iOS 11+ Only physically tested on iOS 14.3 and iOS 12.1.2, but it should support iOS 11 - iOS 15.x (

Dana Buehre 4 Dec 15, 2022
AudiosPlugin is a Godot iOS Audio Plugin that resolves the audio recording issue in iOS for Godot Engine.

This plugin solves the Godot game engine audio recording and playback issue in iOS devices. Please open the Audios Plugin XCode Project and compile the project. You can also use the libaudios_plugin.a binary in your project.

null 3 Dec 22, 2022
AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS, and tvOS.

AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS (including Catalyst), and tvOS. Installation To add AudioKit

AudioKit 9.5k Dec 31, 2022