adamcichy / swiftysound Goto Github PK
View Code? Open in Web Editor NEWSwiftySound is a simple library that lets you play sounds with a single line of code.
License: MIT License
SwiftySound is a simple library that lets you play sounds with a single line of code.
License: MIT License
Because you call the following code where you do, any code that runs after it referencing counter will be off by 1 when calling (players[counter]) directly again.
let player = players[counter]
counter = (counter + 1) % players.count
For example if you want to expose the var currentTime in SwiftySound you would have to do the following:
public var currentTime: TimeInterval {
get {
print("in swifty currentTime: ", self.players**[counter - 1]**.currentTime)
print(self.players[counter - 1].currentTime)
return self.players[counter - 1].currentTime
}
set {
}
}
I think that may be why you're iterating through the entire array of players?
(sorry for spamming your repo with questions :).
This is working for me:
let fileURL = Bundle.main.url(forResource: "MyMusic", withExtension: "mp3")!
Sound.play(url: fileURL) // Music plays
While this is not
let fileURL = Bundle.main.url(forResource: "MyMusic", withExtension: "mp3")!
let mySound = Sound(url: fileURL)!
mySound.play()
I'm running both these snippets in the exact same spot in my code, so I have no idea why one would work and the other wouldn't. May very well be user error, but I think I'm following the documentation correctly.
SwiftySound initialization error: Error Domain=NSOSStatusErrorDomain Code=2003334207 "(null)"
Would it be possible to include an elapsed time in this library, so even if the sound is being looped you can see how long it has been playing for?
Awesome library! Do you think you can further improve with pause and resume method? Thanks!
Hi!
I have distorted sounds when playing for instance an music track with multiple fx sounds at the same time. Create for instance 5 buttons and tap them quickly randomly. A brute cradling noise will appear. My guess it is not from your SwiftySound. Maybe some brick wall limiting in AVFoundation? Maybe memory issue? Turn off noise canceling on the device helps. But doesn't solve all. Types of audio format doesn't help. Different types of setting for the AVAudioSession also doesn't help. Any tips?
regards,
hj
Swift sound forced to set one category, which will conflict with the App's sound category settings.
When app enter backgound ,the music will stop. Is there exits any solutions?
In my game I use different sounds for enemies.
After a specific time the player is not able to play any new sounds and also the older ones might not finish playing or are interrupted.
is there a way to just clean all the memory from sounds so it can start adding sounds anew?
e.g. after every battle a function can be run that all old sounds are removed?
i also have some predefined sounds in a func, should I remove this, or would this not matter? like:
func playTrapSound() {
Sound.play(file: "hitTrap", fileExtension: "mp3", numberOfLoops: 0)
}
Any help appreciated!
Hi, great library!
Is it possible to queue multiple sound files, else it would be a great feature.
/cheers
Hi,
I'm using SwiftySound and I've noticed that when I play a sound, it occasionally stops out of a sudden. It does not always occur, only sometimes. When it does, it seems to happen at a random duration and is unpredictable.
I'm using Sound.play(file: "Timer.m4a")
to play and Sound.stop(file: "Timer.m4a")
to stop the sound. I've uploaded the audio file here.
Any help would be much appreciated, thanks!
In previous projects I used to preload sounds. As I didn't find any mention of this for SwiftySound I wonder if it's a missing part.
First: thank you for this library! Super helpful.
Second: I may be doing something very silly.
I have a sound in an mp3 file. When I play it using the Sound class, it works:
let audioUrl = "path/that/works.mp3"
Sound.play(url:audioUrl)
However, if I try to play from an instance of a sound object, it does not actually play any sound (and does not ever call back a completion event):
let audioUrl = "path/that/works.mp3"
let mySound = Sound(url: audioUrl)
mySound!.play()
Any clues as to what might be going on? When I debug and follow the control flow it seems to be calling all the right things, ultimately ending on return play()
in line 353 of Sound.swift
Thoughts appreciated.
On IOS 14 (maybe earlier versions as well) changing the AVAudioSession's category utilizing Sound.category doesn't seem to work as intended.
If you would like to disable playing simultaneous audio tracks and want to switch to only playing one at a time, you should be able to set the category to .playback or .soloAmbient to disable "mixing". When changing the category however, audio still mixes.
By the way, loving this library thus far as it has saved me a lot of time, thank you!
Xcode SPM import error:
The package dependency graph can not be resolved, possibly because of these requirements:
https://github.com/adamcichy/SwiftySound.git โ 1.1.0..<2.0.0
Using WWDC19 Beta 3 across the board.
This may not be an issue, for my part, so I confirmed the problem in the example in this repo.
Whether or not the code conversion process is performed, the example code (using either the original version 0.5 or the latest 0.7), there is an error, but the build will still compile. Using the pod in a custom project has this same issue:
import SwiftySound
results in "Cannot load underlying module for 'SwiftySound'"
The example works in the simulator, however, as does a custom project also runs on a device.
Hello,
I was running into the issue that after I play a sound for the fifth time by clicking a button using the Sound.play(file: "X.mp3") method, it doesn't start from it's very beginning and just seems to play at a random point.
Best regards
Hi
Is it possible to use SwiftySound with a pageControl? I mean for example launching a sound when someone swipe to a new page, without having to press a play button? thx for your feedback on that
How can I import this module once I installed it with CocoaPods?
Is there a way to crossfade a track when its looped? I need my tracks to sound like infinite.
It is very nice and simple to play sound, thanks for your works.
Could it add some status for the sound - playing / pause / stop?
The issue related here is still alive.
awesome library, would be nice to have Swift 4 and a ".swift-version" file.
I'm always getting this type of error, anyone knows why?
AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Unknown selected data source for Port Speaker (type: Speaker)
I'm creating a soundboard that has 112 sounds right now, however when I try to play them all one after another they stop working after the 50th sound. No matter what order I play the sounds, after 50 they stop working. Is there a max amount of sounds that can load, and if so how can I increase that limit?
Can you do this?
What if it has completion handler as soon as the sound is finish playing?
I created an instance of a sound and when I need to play it again I'm using the same instance to replay it. What I've noticed that is that if I have a completion block for this sound instance the completion block is only called the first time the sound is played. If I play the sound again the completion block is not called again.
Sound init?(url: URL) is crashing when loading a sound in iOS 11 GM. It is called like this:
scanSound = Sound(url: Bundle.main.url(forResource: "beep-sound", withExtension: "mp3")!)
The file exists and the URL is not nil.
This is more of a feature request:
Would it be possible to add a fade out option with a parameter for how long the fade out should be when calling the stopall function?
The use cases would be when using the loop function for multiple playing files you may want to fade out those sounds instead of stopping them at once.
It works when I use the class method.
Sound.play(file: "ding.wav")
But it doesn't work when I use the code below.
I tested on multiple devices.
guard let soundUrl = Bundle.main.url(forResource: "ding", withExtension: "wav") else {
print("error with ding url")
return
}
guard let mySound = Sound(url: soundUrl) else {
print("error with my sound object")
return
}
let didPlay = mySound.play() {
completed in
print("completed: \(completed)")
}
// prints true
print("didPlay: \(didPlay)")
Its great we've exposed capturing duration of played file. Can we pass duration back to the file before playing it to restart playing from an supplied duration?
Hi,
We are trying to play mp3 audio file. It stops playing the audio.
Any idea on what's happening?
For some reasons, we implement our code like this.
DispatchQueue(label: "com.staysorted.soundfx").async {
Sound.play(file: sound.filename)
}
Crashed: com.staysorted.soundfx
0 AVFAudio 0x19d7497b8 AVAudioPlayerCpp::AQOutputCallbackCore(OpaqueAudioQueue*, AudioQueueBuffer*) + 432
1 AVFAudio 0x19d748d8c AVAudioPlayerCpp::prepareToPlayQueue() + 224
2 AVFAudio 0x19d748ee4 AVAudioPlayerCpp::playQueue(AudioTimeStamp const*) + 112
3 AVFAudio 0x19d7477c0 AVAudioPlayerCpp::play() + 84
4 AVFAudio 0x19d7108e0 -[AVAudioPlayer play] + 52
5 SwiftySound 0x101602f4c protocol witness for Player.play() -> Bool in conformance AVAudioPlayer (Sound.swift)
6 SwiftySound 0x1016023f8 Sound.play(numberOfLoops : Int) -> Bool (Sound.swift:153)
7 SwiftySound 0x101605124 specialized static Sound.play(url : URL, numberOfLoops : Int) -> Bool (Sound.swift:195)
8 SwiftySound 0x101602640 static Sound.play(file : String, fileExtension : String?, numberOfLoops : Int) -> Bool (Sound.swift)
9 OneReminder 0x1002a08a0 ORSoundFxManager.(playSound(ORSoundFx) -> ()).(closure #1) (ORSoundFxManager.swift:198)
10 libdispatch.dylib 0x1824069e0 _dispatch_call_block_and_release + 24
11 libdispatch.dylib 0x1824069a0 _dispatch_client_callout + 16
12 libdispatch.dylib 0x182414ad4 _dispatch_queue_serial_drain + 928
13 libdispatch.dylib 0x18240a2cc _dispatch_queue_invoke + 884
14 libdispatch.dylib 0x182414fa8 _dispatch_queue_override_invoke + 344
15 libdispatch.dylib 0x182416a50 _dispatch_root_queue_drain + 540
16 libdispatch.dylib 0x1824167d0 _dispatch_worker_thread3 + 124
17 libsystem_pthread.dylib 0x18260f100 _pthread_wqthread + 1096
18 libsystem_pthread.dylib 0x18260ecac start_wqthread + 4
Is iOS 10.2 really required? For what? I'd like to use it for iOS 10.0 at least ...
Trying to do volume control when playing but the only way to do that is through creating a new instance that I then have to keep track of since if it goes out of scope it doesn't play. Perhaps I'm doing it wrong. Ideally I would like to do something like Sound.play(url: url, withVolume:0.3 ....
Is this possible?
Up to 0.7.0 I could load sound files for xcassets. Now it is hard and cumbersome to manually create a URL
out of a NSDataAsset
.
Is there a particular reason for removing this? Would it be bad to at least keep init?(data: Data)
?
Thanks!
Hello. I would like to know if you are going to release a version for Swift 4.2
I installed this with cocoa pods. I'm not sure if I'm doing anything wrong but when I go into the sound.swift file and try to change the playersPerSound over 5 or under 5 it doesn't reflect that change in the app after I build it, it only plays 5 at the same time. I want it at 20, here's what I changed the line of code to look like: public static var playersPerSound: Int = 20 {
Retrieve duration for a given sound. Great for UI animation.
Can I play Internet audio files ๏ผ
Our app plays sound on iOS 10, but after upgrade to iOS 11, the mp3s don't have any sound. They do seem to be "playing" as we can time aspects of the app to see that a event doesn't happen until after the file should have completed. But no volume. We can hear the sound on the simulator but not the iPad or iPhone device. We've played with the volume setting and a few others but no luck. Debugging doesn't show any errors. The sound objects look about right.
Any ideas to debug this?
I'm looking for a audio library for swift which support .ogg audio file format. Just want to make sure if this library support it or not ?
Sound is playing correctly in background but when i want to navigate to another vc, sound stops. By the way i am going to another vc with "dismiss" method.
Hey, first of all thanks for your work, really neat wrapper for playing sounds!
I'm building a metronome and I noticed that there is a small delay when playing a sound for the first time (or more specific: when calling play() the first time on either the Sound class or a Sound object).
Currently I circumvent this issue by playing a sound and immediately stopping it in my viewDidLoad().
If you need more information, drop me a message. Cheers!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.