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

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

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

Building the App - Part 5 - Adding a Link

AVAudioPlayer. avtouch Application

Announcements. Today s Topics

Implementing UI Designs in Interface Builder

Appendix B: Master Code

Chapter 22 TableView TableView. TableView ios. ViewController. Cell TableViewCell TableView

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

Collection Views. Dr. Sarah Abraham

Document Version Date: 1st March, 2015

ITP 342 Mobile App Dev. Connections

CSC 581: Mobile App Development Spring 2018

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

Building Mapping Apps for ios With Swift

WatchKit In-Depth, Part 2

Gerontechnology II. Collecting Smart Phone Sensor Data for Gerontechnology. Using ios

Stream iphone Sensor Data to Adafruit IO

CS193p Spring 2010 Wednesday, May 26, 2010

UI Design and Storyboarding

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

Advanced Notifications

Rx in the real world. 1 Rob Ciolli

News- ipad: ios(swift) Application

ios Development - Xcode IDE

AVAudioRecorder & System Sound Services

Enhancing your apps for the next dimension of touch

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

Mobile Development Lab 3

Social Pinboard: ios(swift) Application

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

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

InterfaceBuilder and user interfaces

ios Tic Tac Toe Game John Robinson at Rowan University

Learn to make ios apps

A Mad Libs app that you will navigate through 3 UIViewControllers to add text that will be shown in a story on the fourth UIViewController.

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

Announcements. Today s Topics

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

Media and Gaming Accessibility

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

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

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

What s New in tvos #WWDC16. App Frameworks. Session 206. Hans Kim tvos Engineer

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

COMP327 Mobile Computing Session: Lecture Set 1a - Swift Introduction and the Foundation Framework Part 2

Delivering an Exceptional Audio Experience

Camera, Events, and Contacts. Dr. Sarah Abraham

Topics in Mobile Computing

ios Application Development Lecture 2: Seminar and Unit 1

COMPLETE TUTORIAL COURSE. Learn to make tvos LE. apps with real-worldam S F

Cocoa Touch Best Practices

Miscellaneous Topics

Mobile Development - Lab 2

ios 9 SDK Development

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

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

CSC 581: Mobile App Development Spring 2019

Assignment I: Concentration

A Vertical Slider for iphone

Building GUIs with UIKit. Kevin Cathey

Mastering UIKit on tvos

ios Memory Deep Dive #WWDC18 Kyle Howarth, Software Engineer James Snee, Software Engineer Kris Markel, Software Engineer

ITP 342 Mobile App Dev. Audio

View Controllers CPRE 388

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

Integrating Game Center into a BuzzTouch 1.5 app

Lecture 8 Demo Code: Cassini Multithreading

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

Beyond Training The next steps of Machine Learning. Chris /in/chrisparsonsdev

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

Building Faster in Xcode

Graphics and Animation

HACKING WITH SWIFT. Practical. ios 10 COMPLETE TUTORIAL COURSE. Learn to develop apps. for ios 10 by building MP. real-world projects E S

Creating Audio Apps for watchos

Apple Watch Docs. Release 0.1. Michael Hahn

Building real time object detection ios application using machine learning

ITP 342 Mobile App Dev. Connections

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

iphone Application Programming Lab 3: Swift Types and Custom Operator + A02 discussion

ADVANCED M A. Learn SiriKit, imessage apps, rich notifications, and more. with real-world projects HACKING WITH SWIFT COMPLETE TUTORIAL COURSE

lecture 10 UI/UX and Programmatic Design cs : spring 2018

Media Playback and Recording. CS193W - Spring Lecture 3

ITP 342 Mobile App Dev. Animation

ios Application Development Lecture 3: Unit 2

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

ITP 342 Mobile App Dev. Web View

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

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

HPE AppPulse Mobile. Software Version: 2.1. Adding AppPulse Mobile to Your ios App

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

The Sensors in your iphone. Dr Alasdair Allan

Registering for the Apple Developer Program

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

Managing Documents In Your ios Apps

Q-1 What is Parsing? Explain XML parsing and JSON parsing with example. OR Explain JSON parsing with example.

ITP 342 Mobile App Dev. Audio

Stanford CS193p. Developing Applications for ios. Spring Stanford CS193p. Spring 2012

User Interfaces. Lecture 15. Application Programming on Mac OS. Hamza Bennani September 4, 2018

Introductory ios Development

Transcription:

Chapter 30 30.1 App App MP3 Don t Download This Song [1] Finder MP3 Xcode UI 1 import UIKit 2 import AVFoundation 3 4 class ViewController: UIViewController { 5 6 var player: AVAudioPlayer? 7 8 override func viewdidload() { 9 super.viewdidload() 10 let mp3path = Bundle.main.path(forResource: 11 "Dont_Download_This_Song", oftype: "mp3") 12 do { 13 player = try AVAudioPlayer(contentsOf: 14 URL(fileURLWithPath: mp3path!)) 15 } catch { 16 player = nil 17 } 18 if player!= nil { 19 player!.stop() 20 player!.currenttime = 0.0 21 player!.play() 22 }

23 } 24 25 override func didreceivememorywarning() { 26 super.didreceivememorywarning() 27 } 28 } 2 AVFoundation [2] 10 ~ 11 MP3 13 AVAudioPlayer 21 player play 30.2 Slider 0.5 ( ) 2 ( ) 1 0 ( ) ~ 1( ) 0 ( ) Switch On Play Pause Stop 1 class ViewController: UIViewController { 2 3 @IBAction func speedchanged(_ sender: UISlider) { 4 if player!= nil { 5 player!.rate = sender.value 6 } 7 }

8 9 @IBAction func volumnchanged(_ sender: UISlider) { 10 if player!= nil { 11 player!.volume = sender.value 12 } 13 } 14 15 @IBOutlet weak var timeslider: UISlider! 16 17 @IBAction func timechanged(_ sender: UISlider) { 18 if player!= nil { 19 player!.currenttime = Double(sender.value) 20 } 21 } 22 23 @IBAction func autoloop(_ sender: UISwitch) { 24 if player!= nil { 25 if sender.ison == true { 26 player!.numberofloops = -1 27 } else { 28 player!.numberofloops = 0 29 } 30 } 31 } 32 33 @IBAction func play(_ sender: UIButton) { 34 if player!= nil { 35 player!.play() 36 } 37 } 38 39 @IBAction func pause(_ sender: UIButton) { 40 if player!= nil { 41 player!.pause() 42 } 43 } 44 45 @IBAction func stop(_ sender: UIButton) { 46 if player!= nil { 47 player!.stop() 48 player!.currenttime = 0.0 49 } 50 } 51 52 var player: AVAudioPlayer? 53 54 override func viewdidload() { 55 super.viewdidload() 56 let mp3path = Bundle.main.path(forResource: 57 "Dont_Download_This_Song", oftype: "mp3") 58 do { 59 player = try AVAudioPlayer(contentsOf: 60 URL(fileURLWithPath: mp3path!)) 61 } catch { 62 player = nil 63 } 64 if player!= nil { 65 player!.stop() 66 player!.currenttime = 0.0 67 player!.numberofloops = 0

68 player!.enablerate = true 69 timeslider.minimumvalue = 0.0 70 timeslider.maximumvalue = Float(player!.duration) 71 } 72 } 73 74 override func didreceivememorywarning() { 75 super.didreceivememorywarning() 76 } 77 } viewdidload AVAudioPlayer 67 numberofloops 0 68 70 Slider 23 ~ 31 numberofloops 30.3 App Info.plist 1 <key>nsapplemusicusagedescription</key> 2 <string> </string> Label Label 1 import UIKit 2 import MediaPlayer 3 4 class ViewController: UIViewController, 5 MPMediaPickerControllerDelegate { 6 7 var player: AVAudioPlayer? 8 9 @IBOutlet weak var label: UILabel! 10 11 @IBAction func selectmusic(_ sender: UIButton) { 12 let mediacontroller = 13 MPMediaPickerController(mediaTypes:.anyAudio) 14 mediacontroller.delegate = self 15 present(mediacontroller, animated: true, completion: nil) 16 } 17 18 func mediapicker(_ mediapicker: MPMediaPickerController, 19 didpickmediaitems mediaitemcollection:mpmediaitemcollection){ 20 let player = MPMusicPlayerController.applicationMusicPlayer() 21 player.setqueue(with: mediaitemcollection) 22 player.play() 23 label.text = player.nowplayingitem?.title 24 dismiss(animated: true, completion: nil) 25 } 26 27 func mediapickerdidcancel(_ mediapicker:mpmediapickercontroller){

28 dismiss(animated: true, completion: nil) 29 } 30 31 override func viewdidload() { 32 super.viewdidload() 33 } 34 35 override func didreceivememorywarning() { 36 super.didreceivememorywarning() 37 } 38 } 2 MediaPlayer 5 ViewController MPMediaPickerControllerDelegate 11 ~ 16 MPMediaPickerController 13 18 ~ 25 mediaitemcollection

30.4 [3] PickerView Button Picker View 1 class ViewController: UIViewController, UIPickerViewDataSource, 2 UIPickerViewDelegate { 3 4 @IBOutlet weak var pickerview: UIPickerView! 5 6 let effects = ["1000", "1001", "1002", "1003", "1004", "1005", 7 "1006", "1008", "1009", "1010"] 8 9 @IBAction func play(_ sender: UIButton) { 10 let sound = UInt32(effects[pickerview.selectedRow(inComponent: 11 0)]) 12 AudioServicesPlaySystemSound(sound!) 13 } 14 15 func numberofcomponents(in pickerview: UIPickerView) -> Int { 16 return 1 17 } 18 19 func pickerview(_ pickerview: UIPickerView, 20 numberofrowsincomponent component: Int) -> Int { 21 return effects.count 22 } 23 24 func pickerview(_ pickerview: UIPickerView, titleforrow row: Int, 25 forcomponent component: Int) -> String? { 26 return effects[row] 27 } 28 29 override func viewdidload() { 30 super.viewdidload() 31 } 32 33 override func didreceivememorywarning() { 34 super.didreceivememorywarning() 35 } 36 } 10 PickerView UInt32 AudioServicesPlaySystemSound 30.5 App App m4v (ReedBook.m4v) Finder Xcode

1 class ViewController: UIViewController { 2 3 @IBAction func play(_ sender: UIButton) { 4 5 let url = Bundle.main.url(forResource: "ReadBook", 6 withextension: "m4v") 7 let vpcontroller = AVPlayerViewController() 8 vpcontroller.player = AVPlayer(url: url!) 9 present(vpcontroller, animated: true) { 10 vpcontroller.player!.play() 11 } 12 } 13 14 override func viewdidload() { 15 super.viewdidload() 16 } 17 18 override func didreceivememorywarning() { 19 super.didreceivememorywarning() 20 } 21 } 5 URL AVPlayerViewController player AVPlayerViewController 30.6 Info.plist 1 <key>nsmicrophoneusagedescription</key> 2 <string> </string> 3 4 <key>nscamerausagedescription</key> 5 <string> </string> 6 7 <key>nsphotolibraryusagedescription</key>

8 <string> </string> 1 import UIKit 2 import MobileCoreServices 3 import Photos 4 5 class ViewController: UIViewController, 6 UIImagePickerControllerDelegate, UINavigationControllerDelegate { 7 8 @IBAction func recordvideo(_ sender: UIButton) { 9 if UIImagePickerController.isSourceTypeAvailable(.camera) { 10 let controller = UIImagePickerController() 11 controller.sourcetype =.camera 12 controller.mediatypes = [kuttypemovie as String] 13 controller.delegate = self 14 present(controller, animated: true, completion: nil) 15 } 16 } 17 18 func imagepickercontroller(_ picker: UIImagePickerController, 19 didfinishpickingmediawithinfo info: [String : Any]) { 20 let path = (info[uiimagepickercontrollermediaurl] as! 21 NSURL).path 22 UISaveVideoAtPathToSavedPhotosAlbum(path!, self, nil, nil) 23 dismiss(animated: true, completion: nil) 24 } 25 26 func imagepickercontrollerdidcancel(_ picker: 27 UIImagePickerController) { 28 dismiss(animated: true, completion: nil) 29 } 30 31 override func viewdidload() { 32 super.viewdidload() 33 } 34 35 override func didreceivememorywarning() { 36 super.didreceivememorywarning() 37 } 38 } [1] Don't Download This Song - MP3 Music, http://www.albinoblacksheep.com/audio/dontdownload [2] AV Foundation - Apple Developer, https://developer.apple.com/av-foundation/ [3] GitHub - TUNER88/iOSSystemSoundsLibrary: List of all system sounds used in ios, https:// github.com/tuner88/iossystemsoundslibrary