From 7cd965b0c0bd0aa66ba0fe7b30e2b38c15d5d801 Mon Sep 17 00:00:00 2001 From: Sherzod Khashimov Date: Thu, 12 Nov 2020 21:27:38 +0500 Subject: [PATCH] audio fixes --- .../SoundExampleViewController.swift | 4 +- .../SwiftFortuneWheel/SwiftFortuneWheel.swift | 2 +- .../Utils/Audio/AudioPlayer.swift | 2 +- .../Utils/Audio/ImpactFeedbackable.swift | 6 +-- .../Utils/Audio/ImpactFeedbacking.swift | 42 ------------------- 5 files changed, 8 insertions(+), 48 deletions(-) delete mode 100644 Sources/SwiftFortuneWheel/Utils/Audio/ImpactFeedbacking.swift diff --git a/Examples/SwiftFortuneWheelDemo-iOS/SwiftFortuneWheelDemo-iOS/ViewControllers/SoundExample/SoundExampleViewController.swift b/Examples/SwiftFortuneWheelDemo-iOS/SwiftFortuneWheelDemo-iOS/ViewControllers/SoundExample/SoundExampleViewController.swift index caefb73..50b0ca2 100644 --- a/Examples/SwiftFortuneWheelDemo-iOS/SwiftFortuneWheelDemo-iOS/ViewControllers/SoundExample/SoundExampleViewController.swift +++ b/Examples/SwiftFortuneWheelDemo-iOS/SwiftFortuneWheelDemo-iOS/ViewControllers/SoundExample/SoundExampleViewController.swift @@ -62,7 +62,7 @@ class SoundExampleViewController: UIViewController { } func rotate() { - fortuneWheel.startRotationAnimation(finishIndex: 0, continuousRotationTime: 5, nil) + fortuneWheel.startRotationAnimation(finishIndex: 0, continuousRotationTime: 2, nil) } @IBAction func impactFeedbackValueChanged(_ sender: UISwitch) { @@ -70,6 +70,8 @@ class SoundExampleViewController: UIViewController { } @IBAction func soundEffectTypeValueChanged(_ sender: UISegmentedControl) { + fortuneWheel.stopRotation() + fortuneWheel.edgeCollisionDetectionOn = soundEffectTypeSegmentedControl.selectedSegmentIndex == 0 fortuneWheel.centerCollisionDetectionOn = soundEffectTypeSegmentedControl.selectedSegmentIndex == 1 diff --git a/Sources/SwiftFortuneWheel/SwiftFortuneWheel.swift b/Sources/SwiftFortuneWheel/SwiftFortuneWheel.swift index 6952f3d..74a5e8a 100644 --- a/Sources/SwiftFortuneWheel/SwiftFortuneWheel.swift +++ b/Sources/SwiftFortuneWheel/SwiftFortuneWheel.swift @@ -103,7 +103,7 @@ public class SwiftFortuneWheel: SFWControl { private(set) lazy var audioPlayerManager = AudioPlayerManager() #if os(iOS) - @available(iOSApplicationExtension 10.0, *) + @available(iOS 10.0, iOSApplicationExtension 10.0, *) private(set) lazy var impactFeedbackgenerator = UIImpactFeedbackGenerator(style: .light) #endif diff --git a/Sources/SwiftFortuneWheel/Utils/Audio/AudioPlayer.swift b/Sources/SwiftFortuneWheel/Utils/Audio/AudioPlayer.swift index a314260..f3088c2 100644 --- a/Sources/SwiftFortuneWheel/Utils/Audio/AudioPlayer.swift +++ b/Sources/SwiftFortuneWheel/Utils/Audio/AudioPlayer.swift @@ -19,7 +19,7 @@ class AudioPlayer { /// - file: Audio file that will be played /// - identifier: Sound identifier which is will start to play func play(_ file: AVAudioFile, identifier: SoundIdentifier) { - if #available(iOSApplicationExtension 11.0, OSXApplicationExtension 10.13, tvOSApplicationExtension 11.0, *) { + if #available(iOS 11.0, iOSApplicationExtension 11.0, OSX 10.13, OSXApplicationExtension 10.13, tvOS 11.0, tvOSApplicationExtension 11.0, *) { node.scheduleFile(file, at: nil, completionCallbackType: .dataPlayedBack) { [weak self] callbackType in self?.didCompletePlayback(for: identifier) diff --git a/Sources/SwiftFortuneWheel/Utils/Audio/ImpactFeedbackable.swift b/Sources/SwiftFortuneWheel/Utils/Audio/ImpactFeedbackable.swift index bd3aaf8..ba0dc54 100644 --- a/Sources/SwiftFortuneWheel/Utils/Audio/ImpactFeedbackable.swift +++ b/Sources/SwiftFortuneWheel/Utils/Audio/ImpactFeedbackable.swift @@ -17,7 +17,7 @@ import UIKit #if os(iOS) /// The protocol that adds support for the impact feedback protocol ImpactFeedbackable { - @available(iOSApplicationExtension 10.0, *) + @available(iOS 10.0, iOSApplicationExtension 10.0, *) /// Use impact feedback to indicate that an impact has occurred var impactFeedbackgenerator: UIImpactFeedbackGenerator { get } /// Impact feedback on or off @@ -27,7 +27,7 @@ protocol ImpactFeedbackable { extension ImpactFeedbackable { /// Prepare impact feedback if needed func prepareImpactFeedbackIfNeeded() { - if #available(iOSApplicationExtension 10.0, *) { + if #available(iOS 10.0, iOSApplicationExtension 10.0, *) { guard impactFeedbackOn == true else { return } impactFeedbackgenerator.prepare() } else { @@ -37,7 +37,7 @@ extension ImpactFeedbackable { /// Generates impact feedback func impactFeedback() { - if #available(iOSApplicationExtension 10.0, *) { + if #available(iOS 10.0, iOSApplicationExtension 10.0, *) { if impactFeedbackOn { impactFeedbackgenerator.impactOccurred() } diff --git a/Sources/SwiftFortuneWheel/Utils/Audio/ImpactFeedbacking.swift b/Sources/SwiftFortuneWheel/Utils/Audio/ImpactFeedbacking.swift deleted file mode 100644 index ab51ffa..0000000 --- a/Sources/SwiftFortuneWheel/Utils/Audio/ImpactFeedbacking.swift +++ /dev/null @@ -1,42 +0,0 @@ -// -// ImpactFeedbacking.swift -// SwiftFortuneWheel -// -// Created by Sherzod Khashimov on 11/2/20. -// Copyright © 2020 SwiftFortuneWheel. All rights reserved. -// - -import Foundation - -#if os(macOS) -import AppKit -#else -import UIKit -#endif - -protocol ImpactFeedbackable { - @available(iOSApplicationExtension 10.0, *) - var impactFeedbackgenerator: UIImpactFeedbackGenerator { get } - var impactFeedbackOn: Bool { get set } -} - -extension ImpactFeedbackable { - func prepareImpactFeedbackIsNeeded() { - if #available(iOSApplicationExtension 10.0, *) { - guard impactFeedbackOn == true else { return } - impactFeedbackgenerator.prepare() - } else { - // Fallback on earlier versions - } - } - - func impactFeedback() { - if #available(iOSApplicationExtension 10.0, *) { - if impactFeedbackOn { - impactFeedbackgenerator.impactOccurred() - } - } else { - // Fallback on earlier versions - } - } -}