Skip to content

Instantly share code, notes, and snippets.

@gHashTag
Last active April 5, 2017 19:28
Show Gist options
  • Save gHashTag/fd006b8c09b534a79e5f531c45089aa5 to your computer and use it in GitHub Desktop.
Save gHashTag/fd006b8c09b534a79e5f531c45089aa5 to your computer and use it in GitHub Desktop.
//
// ViewController.swift
// Raketa-iOS
//
// Created by Dmitriy Vasilev on 04.04.17.
// Copyright © 2017 gHashTag. All rights reserved.
//
import UIKit
import AVFoundation
class ViewController: UIViewController {
static var Group: [AVAudioPlayer]!
var drums1 = AVAudioPlayer()
var drums2 = AVAudioPlayer()
var drums3 = AVAudioPlayer()
var drums4 = AVAudioPlayer()
var drums5 = AVAudioPlayer()
var drums6 = AVAudioPlayer()
var drums7 = AVAudioPlayer()
var drums8 = AVAudioPlayer()
var drums9 = AVAudioPlayer()
var drums10 = AVAudioPlayer()
var drums11 = AVAudioPlayer()
var drums12 = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
do {
drums1 = try AVAudioPlayer(contentsOf: URL.init(fileURLWithPath: Bundle.main.path(forResource: "S1_CRASH_FILL_BD_SN", ofType: "wav")!))
drums2 = try AVAudioPlayer(contentsOf: URL.init(fileURLWithPath: Bundle.main.path(forResource: "S1_Main_BD", ofType: "wav")!))
drums3 = try AVAudioPlayer(contentsOf: URL.init(fileURLWithPath: Bundle.main.path(forResource: "S1_Main_BD_SN", ofType: "wav")!))
drums4 = try AVAudioPlayer(contentsOf: URL.init(fileURLWithPath: Bundle.main.path(forResource: "S2_BD_BASS", ofType: "wav")!))
drums5 = try AVAudioPlayer(contentsOf: URL.init(fileURLWithPath: Bundle.main.path(forResource: "S2_BD_BASS_SN", ofType: "wav")!))
drums6 = try AVAudioPlayer(contentsOf: URL.init(fileURLWithPath: Bundle.main.path(forResource: "S2_CRASH_FILL_BD_B_SN", ofType: "wav")!))
drums7 = try AVAudioPlayer(contentsOf: URL.init(fileURLWithPath: Bundle.main.path(forResource: "S3_BD_BASS", ofType: "wav")!))
drums8 = try AVAudioPlayer(contentsOf: URL.init(fileURLWithPath: Bundle.main.path(forResource: "S3_BD_BASS_SN", ofType: "wav")!))
drums9 = try AVAudioPlayer(contentsOf: URL.init(fileURLWithPath: Bundle.main.path(forResource: "S3_CRASH_FILL_BDBSN", ofType: "wav")!))
drums10 = try AVAudioPlayer(contentsOf: URL.init(fileURLWithPath: Bundle.main.path(forResource: "S4_BD_Sub_BD_SN", ofType: "wav")!))
drums11 = try AVAudioPlayer(contentsOf: URL.init(fileURLWithPath: Bundle.main.path(forResource: "S4_BD_Sub_BD", ofType: "wav")!))
drums12 = try AVAudioPlayer(contentsOf: URL.init(fileURLWithPath: Bundle.main.path(forResource: "S4_CRASH_FILL_BDSN", ofType: "wav")!))
ViewController.Group = [
drums1,
drums2,
drums3,
drums4,
drums5,
drums6,
drums7,
drums8,
drums9,
drums10,
drums11,
drums12,
]
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(AVAudioSessionCategoryPlayback)
}
}
catch {
print(error)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
static func loop(_ avPlayer: AVAudioPlayer) {
avPlayer.prepareToPlay()
avPlayer.numberOfLoops = -1
avPlayer.play()
}
static func playSound1() {
let r = Int(arc4random_uniform(12))
ViewController.loop((ViewController.Group[r]))
}
static func stopSound1() {
let r = Int(arc4random_uniform(12))
ViewController.loop((ViewController.Group[r])).stop()
}
@IBAction func Play(_ sender: Any) {
ViewController.playSound1()
}
@IBAction func Stop(_ sender: Any) {
ViewController.stopSound1()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment