Pianoのアプリ
小学生ならアプリが作れるかな
好きなミュージクを簡単にプレイできる
小学生から柔らかな頭脳が育成される
iPhoneでPianoを作ってみましょう。
AppleのMac PCがあれば誰でも楽しめます、Pianoのアプリ
開発の手順:
1) 画面デザインをする
2) 画面に対応したプログラム・ファイルを作成する
3) 画面のパーツ( ボタン)とプログラムの接続をする
4) 音源、イメージ・フォトを用意する
5) 画面ごとのクラスに下記のコードを作成する
// Created by Satoshi Sato on 2016/08/08.
// Copyright © 2016年 Satoshi Sato. All rights reserved.
//
import UIKit
//1 import AVFoundation
import AVFoundation
class ViewController1: UIViewController {
//2 Set AVAudioPlayer
var player:AVAudioPlayer = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
//4 Action to play sound by Keyboard
@IBAction func keyBoardTatched(sender: UIButton) {
// Get keyboard code, such as C, D, etc
let titleValueString = sender.currentTitle!
print(titleValueString)
switch titleValueString {
// If keyboaed is "F3", then play sound, ff-33.wav
case "F3" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-33", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.7
player.play()
case "F3#" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-34", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "G3" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-35", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "G3#" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-36", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "A3" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-37", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "B3b" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-38", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "B3" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-39", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "C4" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-40", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "C4#" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-41", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "D4" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-42", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "E4b" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-43", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "E4" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-44", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "F4" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-45", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "F4#" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-46", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "G4" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-47", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "G4#" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-48", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "A4" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-49", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "B4b" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-50", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "B4" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-51", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "C5" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-52", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "C5#" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-53", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "D5" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-54", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "E5b" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-55", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "E5" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-56", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
case "F5" :
let audioPath = NSBundle.mainBundle().pathForResource("ff-57", ofType: "wav")
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
player.currentTime = 0.0
player.volume = 0.5
player.play()
default : break
}
}
}
// Created by Satoshi Sato on 2016/08/08.
// Copyright © 2016年 Satoshi Sato. All rights reserved.
//
import UIKit
//1 Set AVFoundation
import AVFoundation
class ViewController2: UIViewController {
//2 Set AVAudioPlayer
var player:AVAudioPlayer = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
//3 Set Sound
let audioPath = NSBundle.mainBundle().pathForResource("pop", ofType: "mp3")
let error : NSError? = nil
print(error)
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
}
catch {
print("errors")
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//4
@IBAction func play(sender: UIButton) {
player.play()
}
//5
@IBAction func stop(sender: UIButton) {
player.stop()
// set initial start point
player.currentTime = 0.0
}
//6
@IBAction func Pause(sender: UIButton) {
player.pause()
}
}
オフィス・イニシアティブ
代表 佐藤 聖
神奈川県足柄下郡箱根町強羅1300-169-110
Office Initiative
Representative: Satoshi Sato
iPhoneのアプリ開発に関して Youtubeでみてください