AVAudioRecorder & System Sound Services

Similar documents
ITP 342 Mobile App Dev. Audio

AVAudioPlayer. avtouch Application

iphone Programming Touch, Sound, and More! Norman McEntire Founder Servin Flashlight CodeTour TouchCount CodeTour

CS193P - Lecture 16. iphone Application Development. Audio APIs Video Playback Displaying Web Content Settings

Integrating Game Center into a BuzzTouch 1.5 app

IOS - TEXT FIELD. Use of Text Field. Important Properties of Text Field. Updating Properties in xib

Multimedia. Mobile Application Development in ios School of EECS Washington State University Instructor: Larry Holder

Widget Tour. iphone and ipod touch Development Fall 2009 Lecture 7

Delivering an Exceptional Audio Experience

ITP 342 Mobile App Dev. Audio

Announcements. Today s Topics

iphone App Basics iphone and ipod touch Development Fall 2009 Lecture 5

Using Advanced Interface Objects and Views

Navigation bar (Xcode version 4.5.2) 1. Create a new project. From the Xcode menu, select File > New > Project

CS193p Spring 2010 Wednesday, May 26, 2010

ITP 342 Mobile App Dev. Connections

Announcements. Today s Topics

ios Core Data Example Application

} override func didreceivememorywarning() { 26 super.didreceivememorywarning() 27 } 28 } Pause Stop

Multitasking and Background Execution

Corrections and version notes

Localizing with Xcode 6

iphone Application Tutorial

My First iphone App. 1. Tutorial Overview

Designing iphone Applications

Step 1: Open Xcode and select Create a new Xcode Project from the Welcome to Xcode menu.

ITP 342 Mobile App Dev. Animation

CS193P: HelloPoly Walkthrough

iphone Programming Patrick H. Madden SUNY Binghamton Computer Science Department

Your First iphone OS Application

ITP 342 Mobile App Dev. Web View

ITP 342 Advanced Mobile App Dev. Memory

ITP 342 Mobile App Dev. Connections

Topics in Mobile Computing

View Controllers CPRE 388

Contents. iphone Training. Industry Trainers. Classroom Training Online Training ON-DEMAND Training. Read what you need

Objective-C Primer. iphone Programmer s Association. Lorenzo Swank September 10, 2008

View Controller Lifecycle

Your First iphone Application

My First iphone App (for Xcode version 6.4)

Objectives. Submission. Register for an Apple account. Notes on Saving Projects. Xcode Shortcuts. CprE 388 Lab 1: Introduction to Xcode

Running Code on an ios Device. Appendix. The ios Developer Program

OVERVIEW. Why learn ios programming? Share first-hand experience. Identify platform differences. Identify similarities with.net

InterfaceBuilder and user interfaces

Life Cycle. Chapter Explore the Game Application. Understanding the Views in a Game

Implementing UI Designs in Interface Builder

Mobile Apps 2010 iphone and Android

Developing Applications for ios

Intro to Native ios Development. Dave Koziol Arbormoon Software, Inc.

The MVC Design Pattern

src3/bettertextfield/bettertextfield/appdelegate.h // AppDelegate.h // BetterTextField

ITP 342 Mobile App Dev. Fundamentals

Assignment II: Foundation Calculator

A Vertical Slider for iphone

Using Swift with Cocoa and Objective-C

Web 2.0 and iphone Application Development Workshop. Lab 2: iphone programming basics

epicurious Anatomy of an ios app Robert Tolar Haining June 25, 2010 ConvergeSE

Create an App that will drop PushPins onto a map based on addresses that the user inputs.

COPYRIGHTED MATERIAL. part I Developing a Professional UI. Chapter 1: Creating a Personal Library. Chapter 2: Advancing with Tableviews

Assignment I Walkthrough

ios 101 Hands-On Challenges

ITP 342 Mobile App Dev. Interface Builder in Xcode

Why Model-View-Controller?

What s New in Core Audio

View Concepts. iphone Application Programming Lecture 4: User Interface Design. SDK provide many types of Views to show your content

Covers ios 6. Bear Cahill. Includes 98 Techniques MANNING

1 Build Your First App. The way to get started is to quit talking and begin doing. Walt Disney

Web 2.0 and iphone Application Development Workshop. Lab 5: Multimedia on iphone

Document Version Date: 1st March, 2015

MVC and Interface Builder IAP 2010

App SandBox Directory

ITP 342 Advanced Mobile App Dev. Core Data

A Mobile Mapping Application

Building the App - Part 5 - Adding a Link

Review. Objective-C Classes, Methods, Properties, Protocols, Delegation, Memory Management

Building GUIs with UIKit. Kevin Cathey

The Sensors in your iphone. Dr Alasdair Allan

ITP 342 Mobile App Dev

Playing & Recording Audio Audio Queue Services Playback - AQPlayer Class

Stanford CS193p. Developing Applications for iphone 4, ipod Touch, & ipad Fall Stanford CS193p Fall 2010

Stanford CS193p. Developing Applications for ios. Fall Stanford CS193p. Fall 2011

ios Developer s Guide Version 1.0

ios 9 SDK Development

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar

Data Management

Cisco StadiumVision Mobile API for Apple ios

CS193E Lecture 7. Document-based Applications NSTableView Key-Value Coding

Tip Calculator App Introducing Swift, Text Fields, Sliders, Outlets, Actions, View Controllers, Event Handling, NSDecimalNumber,

App. Chapter 19 App. App (ViewController) App. Single View Application Single View Application View. (View Controller)

Media Playback and Recording. CS193W - Spring Lecture 3

Cisco StadiumVision Mobile API for Apple ios

ios 7 App Development Essentials

lectures/2/src2/nib1/nib1/appdelegate.h // AppDelegate.h // Nib1 // David J. Malan // Harvard University //

Developing Applications for ios

MBS Xojo AudioPlayer Kit

Audio Queue Services. Dave

ios DeCal : Lecture 2 Structure of ios Applications: MVC and Auto Layout

CS 47. Beginning iphone Application Development

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

Creating Audio Apps for watchos

Transcription:

AVAudioRecorder & System Sound Services Dept. of Multimedia Science, Sookmyung Women s University. prof. JongWoo Lee Index AVAudioRecorder? - (AudioRecorder) System Sound Service? - (SysSound)

AVAudioRecorder AVAudioRecorder? ( Audio Queue Services ) NSMutableData object audio recorder - Record until the user stops the recording - Record for a specified duration - Pause and resume a recording - Obtain input audio-level data that you can use to provide level metering AVAudioRecorder Class Inherits Conforms to NSObect NSObect(NSObject) Framework Availability Declared in /System/Library/Frameworks/AVFoundation.framework Available in ios 3.0 and later AVAudioRecorder.h

3 AVAudioSession AVAudioPlayer, AVAudioRecorder AVAudioRecorder : AudioRecorder Begin Recording Stop Recording Start Recording Play Recording

Xcode_ Xcode file-new Project View-based Application choose AudioRecorder Save Interface Builder_UI AudioRecorderViewController.xib Interface Builder View UI 1. View Attributes background 2. Library Round Rect Button 2 Activity Indicator View Label ( ) : Interface Builder View UI Xcode

Xcode_AudioRecorderViewController.h Classes 4 AudioRecorderViewController.h Interface Builder UI #import <UIKit/UIKit.h> #import <AVFoundation/AVFoundation.h> #import <CoreAudio/CoreAudioTypes.h> @interface record_audio_testviewcontroller : UIViewController <AVAudioRecorderDelegate> { IBOutlet UIButton * btnstart; IBOutlet UIButton * btnplay; IBOutlet UIActivityIndicatorView * actspinner; BOOL toggle; // begin/start NSURL * recordedtmpfile; AVAudioRecorder * recorder; NSError * error; @property (nonatomic,retain)iboutlet UIActivityIndicatorView * actspinner; @property (nonatomic,retain)iboutlet UIButton * btnstart; @property (nonatomic,retain)iboutlet UIButton * btnplay; // - (IBAction) start_button_pressed; // - (IBAction) play_button_pressed; // @end : Xcode_AudioRecorderViewController.m Classes 4 AudioRecorderViewController.m 1. viewdidload{ #import "AudioRecorderViewController.h" @implementation AudioRecorderViewController @synthesize actspinner, btnstart, btnplay; //nib - (void)viewdidload { [super viewdidload]; toggle = YES; //toggle true mode btnplay.hidden = YES; // play button //AVAudioSession object instance AVAudioSession * audiosession = [AVAudioSession sharedinstance]; // audiosession //AudioSession AVAudioSesseionCategoryPlayAndRecord [audiosession setcategory:avaudiosessioncategoryplayandrecord error: &error]; [audiosession setactive:yes error: &error]; //

Xcode_AudioRecorderViewController.m 2. start_button_pressed{ - (IBAction) start_button_pressed{ if(toggle) { toggle = NO; [actspinner startanimating]; [btnstart settitle:@"stop Recording" forstate: UIControlStateNormal ]; btnplay.enabled = toggle; btnplay.hidden = toggle; //recording session //dictionary object setup NSMutableDictionary* recordsetting = [[NSMutableDictionary alloc] init]; [recordsetting setvalue :[NSNumber numberwithint:kaudioformatappleima4] forkey:avformatidkey]; // recordedtmpfile = [NSURL fileurlwithpath:[nstemporarydirectory() stringbyappendingpathcomponent: [NSString stringwithformat: @"%.0f.%@", [NSDate timeintervalsincereferencedate] * 1000.0, @"caf"]]]; //Setup the recorder to use this file and record to it. recorder = [[ AVAudioRecorder alloc] initwithurl:recordedtmpfile settings:recordsetting error:&error]; // recorder [recorder setdelegate:self]; // // [recorder preparetorecord]; // [recorder record]; Xcode_AudioRecorderViewController.m 2. start_button_pressed{ ( ) else { toggle = YES; [actspinner stopanimating]; [btnstart settitle:@"start Recording" forstate:uicontrolstatenormal ]; btnplay.enabled = toggle; btnplay.hidden = toggle; //Stop the recorder. [recorder stop]; 3. play_button_pressed{ -(IBAction) play_button_pressed{ //play // AVAudioPlayer AVAudioPlayer * avplayer = [[AVAudioPlayer alloc] initwithcontentsofurl:recordedtmpfile error:&error]; [avplayer preparetoplay]; [avplayer play];

Xcode_AudioRecorderViewController.m 4. viewdidunload{ - (void)viewdidunload { //main view subview // e.g. self.myoutlet = nil; // NSFileManager * fm = [NSFileManager defaultmanager]; [fm removeitematpath:[recordedtmpfile path] error:&error]; // object dealloc [recorder dealloc]; recorder = nil; recordedtmpfile = nil; Build and Run... AVAudioSession audiosession AVAudioSessionCategoryPlayAndRecord kaudioformatappleima4 AVFormatIDKey. Framework - AVFoundation.framework - CoreAudio.framework

Framework AudioRecorderViewController.h import #import <CoreAudio/CoreAudioTypes.h> #import <AVFoundation/AVFoundation.h> Groups & Files Frameworks CoreAudio, AVFoundation Add Xcode Interface Builder (1/4) AudioRecorderViewController.xib Interface Builder 1. View File s Owner. 2. xib File s Owner Outlet. 3. Begin Recording Play Recording. 4. Activity Indicator View. 1. View File s Owner File s Owner View File s Owner control View

Xcode Interface Builder (2/4) 2. xib File s Owner Outlet. File s Owner Inspector Audio Recorder View Controller Connections Xcode Outlet View Activity Indicator Xcode Interface Builder (3/4) 3. Begin Recording Play Recording Begin Recording Inspector Button Connections Touch Up Inside File s Owner start_button_pressed Play Recording Touch Up Inside File s Owner play_button_pressed

Xcode Interface Builder (4/4) 4. Activity Indicator View Activity Indicator View Hide When Stopped Xcode Build & Run &

Q. Simulator...? imac?? ~

System Sound Service System Sound Service(1/3) level, positioning, audio session - 30 - Linear PCM IMA4(IMA/ADPCM) -.caf,.aif.wav playback method - AudioServicesPlaySystemSound ( ) - AudioServicesPlayAlertSound ( ) Declared in AudioServices.h in Audio Toolbox framework

System Sound Service(2/3) Functions by Task Creating and Disposing of System Sound Objects Playing Sounds Adding and Removing System Sound Callbacks AudioServicesCreateSystemSoundID AudioServicesDisposeSystemSoundID AudioServicesPlayAlertSound AudioServicesPlaySystemSound AudioServicesAddSystemSoundCompletion AudioServicesRemoveSystemSoundCompletion AudioServicesPlaySystemSound - very simply play short sound files - Sounds play at the current system audio volume, with no programmatic volume control available - Sounds play immediately - Looping and stereo positioning are unavailable - Simultaneous playback is unavailable: You can play only one sound at a time iphone ( ) - AudioServicesPlaySystemSound ksystemsoundid_vibrate System Sound Service(3/3) AudioServicesPlaySystemSound 1. sound ID object 2. then,. : SysSound tap.aif.

Xcode_ Xcode file-new Project View-based Application choose AudioRecorder Save AudioRecorder Interface Builder SysSoundViewController.xib AudioToolbox.framework Xcode_SysSoundViewController.h Classes 4 SysSoundViewController.h #import <UIKit/UIKit.h> #include <AudioToolbox/AudioToolbox.h> @interface SysSoundViewController : UIViewController { CFURLRef soundfileurlref; SystemSoundID soundfileobject; @property (readwrite) CFURLRef soundfileurlref; @property (readonly) SystemSoundIDsoundFileObject; //UI - (IBAction) playsystemsound: (id) sender; - (IBAction) playalertsound: (id) sender; - (IBAction) vibrate: (id) sender; @end :

Xcode_SysSoundViewController.m Classes 4 SysSoundViewController.m 1. viewdidload{ #import "SysSoundViewController.h" @implementation SysSoundViewController @synthesize soundfileurlref; @synthesize soundfileobject; - (void) viewdidload { [super viewdidload]; // Provide a nice background for the app user interface.( nice background) self.view.backgroundcolor = [UIColor grouptableviewbackgroundcolor]; // URL NSURL *tapsound = [[NSBundle mainbundle] URLForResource: @"tap" withextension: @"aif"]; // CFURLRef instance URL self.soundfileurlref = (CFURLRef) [tapsound retain]; // AudioServicesCreateSystemSoundID ( ); soundfileurlref, &soundfileobject Xcode_SysSoundViewController.m 2. // System Sound button - (IBAction) playsystemsound: (id) sender { AudioServicesPlaySystemSound (soundfileobject); // Alert Sound button - (IBAction) playalertsound: (id) sender { AudioServicesPlayAlertSound (soundfileobject); // Vibrate button, - (IBAction) vibrate: (id) sender { AudioServicesPlaySystemSound (ksystemsoundid_vibrate); // - (void) dealloc { AudioServicesDisposeSystemSoundID (soundfileobject); CFRelease (soundfileurlref); [super dealloc];

Xcode Interface Builder & SysSoundViewController.xib Interface Builder 1. View File s Owner. 2. xib File s Owner Outlet. 3. System Sound, Alert Sound Vibration. Xcode. - wav ( test.wav )