Ребята, как сделать чтобы звук зацикливался, повторялся при окончании ?
И втрой вопрос: Как сделать чтобы эта мелодия при передвижении ползунка в зависимости от его положения играла тише / громче ?
import UIKit
import AVFoundation
import AudioToolbox
class ViewController: UIViewController {
@IBOutlet weak var StartButton: UIButton!
@IBOutlet weak var StopButton: UIButton!
@IBOutlet weak var Slider: UISlider!
let popSound = Bundle.main.url(forResource: "401275__inspectorj__rain-moderate-c", withExtension: "wav")
var audioPlayer = AVAudioPlayer()
override func viewDidLoad() {
Slider.value = 50
Slider.maximumValue = 100
Slider.minimumValue = 0
Slider.layer.cornerRadius = 10
StartButton.backgroundColor = .black
StartButton.layer.cornerRadius = 10
StartButton.frame = CGRect(x: 45, y: 90, width: 100 , height: 100)
StartButton.layer.cornerRadius = 10
StartButton.setTitleColor(#colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0), for: .normal)
StopButton.backgroundColor = .blue
StopButton.frame = CGRect(x: 240, y: 90, width: 100 , height: 100)
StopButton.layer.cornerRadius = 10
StopButton.setTitleColor(#colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0), for: .normal)
}
@IBAction func playSound(_ sender: UIButton) {
do {
audioPlayer = try AVAudioPlayer(contentsOf: popSound!)
audioPlayer.play()
} catch {
print("couldn't load sound file")
}
}
@IBAction func StopPlay(_ sender: UIButton) {
do {
audioPlayer = try AVAudioPlayer(contentsOf: popSound!)
audioPlayer.stop()
} catch {
print("couldn't load sound file")
}
}
@IBAction func SliderMovie(_ sender: UISlider) {
if Slider.value > 50 {
do {
audioPlayer = try AVAudioPlayer(contentsOf: popSound!)
audioPlayer.play()
} catch {
print("couldn't load sound file")
}
} else {
do {
audioPlayer = try AVAudioPlayer(contentsOf: popSound!)
audioPlayer.stop()
} catch {
print("couldn't load sound file")
}
}
}
}