Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Fix and expose volume attribute from convenience methods #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Sources/Sound.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ open class Sound {
/// - fileExtension: Sound file extension.
/// - numberOfLoops: Number of loops. Specify a negative number for an infinite loop. Default value of 0 means that the sound will be played once.
/// - Returns: If the sound was played successfully the return value will be true. It will be false if sounds are disabled or if system could not play the sound.
@discardableResult public static func play(file: String, fileExtension: String? = nil, numberOfLoops: Int = 0) -> Bool {
@discardableResult public static func play(file: String, fileExtension: String? = nil, numberOfLoops: Int = 0, volume: Float = 1.0) -> Bool {
if let url = url(for: file, fileExtension: fileExtension) {
return play(url: url, numberOfLoops: numberOfLoops)
return play(url: url, numberOfLoops: numberOfLoops, volume: volume)
}
return false
}
Expand All @@ -236,13 +236,14 @@ open class Sound {
/// - url: Sound file URL.
/// - numberOfLoops: Number of loops. Specify a negative number for an infinite loop. Default value of 0 means that the sound will be played once.
/// - Returns: If the sound was played successfully the return value will be true. It will be false if sounds are disabled or if system could not play the sound.
@discardableResult public static func play(url: URL, numberOfLoops: Int = 0) -> Bool {
@discardableResult public static func play(url: URL, numberOfLoops: Int = 0, volume: Float = 1.0) -> Bool {
if !Sound.enabled {
return false
}
var sound = sounds[url]
if sound == nil {
sound = Sound(url: url)
sound?.volume = volume
sounds[url] = sound
}
return sound?.play(numberOfLoops: numberOfLoops) ?? false
Expand Down Expand Up @@ -301,7 +302,7 @@ open class Sound {
}

/// Player protocol. It duplicates `AVAudioPlayer` methods.
public protocol Player: class {
public protocol Player: AnyObject {

/// Play the sound.
///
Expand Down