nicklockwood / soundmanager Goto Github PK
View Code? Open in Web Editor NEWSimple sound and music player class for playing audio on Mac and iPhone
Home Page: http://www.charcoaldesign.co.uk/source/cocoa#soundmanager
License: Other
Simple sound and music player class for playing audio on Mac and iPhone
Home Page: http://www.charcoaldesign.co.uk/source/cocoa#soundmanager
License: Other
When my device is muted, the sounds still play for a second and then stops. Any suggestions how to stop that. Thanks
Can SoundManager play sound from url on the internet, can you show me how to do this
This seems to be unhandled situation, or maybe I am not aware of some features which handle this situation...When app returns from background, music is stopped, and I can't resume it.
I am guessing that this is related to AVAudioSession...
@nicklockwood Do you have some idea how to handle this and make music continue from where it is stopped (or at least to start it from beginning) ?
This can be produced by simply running your sample project -> play music -> receive phone-call (so I am sure that is nothing wrong with my code, because I use your sample app).
Any thoughts ?
Best Regards,
Vladimir
Local disk caching,
user only needs to stream a file once and after that it can be played from a local cache
Hello,
I play a sound first, after that I try to stop sound or all sounds but the soundmanager continue play the sound.
Mac OS 10.9
Is it possible to adjust the pitch of a sound? For example, I could record a "Do" in "Do Re Mi", then I adjust the pitch of the "Do" to create "Do Re Mi Fa So ...".
As a standard practice, the SoundManager should have a 3-letter prefix. The effects of NOT having this were once again made clear to me when my linker failed because there was another third-party library that also had a class called SoundManager. My code won't run until this is fixed.
I've got a music loop on the main viewController with a sound button to control turning the music on/off;
I stop the music on the primary viewController [music fades out and stops] and press another button to load a tableView controller. I drill down through the tableView into a detailTableView and so far so good, no music. However I then click on a button within the detailTableView to push up a different viewController and the music starts up again. Any idea why that's happening?
Hi Nick,
First of all, thanks for the library.
I've developed an app with it, but for some reason, on some devices, it doesn't generate sound unless I plug the headphones.
Have you heard this issue before?
Thanks again.
Started working with Sound Manager this morning, and when running in the iOS Simulator (8.3, 8.4 and 9.0), a fatal crash is experienced on this line:
[[SoundManager sharedManager] prepareToPlay];
I am calling with
[SoundManager sharedManager].allowsBackgroundMusic = YES;
[SoundManager sharedManager].soundFadeDuration = 1.0f;
[[SoundManager sharedManager] prepareToPlay];
Crash is also occurring with
[[SoundManager sharedManager] prepareToPlayWithSound:[Sound soundNamed:kSISoundFXInitalize]];
Thanks so much for making your wonderful class available to use,
its amazing and very convenient!
I had a little problem with the array deleting sounds while enumerating,
( the sound clips are narration played over BG music so are longer than a sound effect, maybe thats the problem...)
being super new to coding ill add my solution (it wont be as elegant as your code)
but maybe it will help someone, or at least make you aware of the issue
hope I did the right thing! - it dosnt seem to crash anymore
with many thanks
N
:)
(void)stopSound:(id)soundOrName fadeOut:(BOOL)fadeOut
{
if ([soundOrName isKindOfClass:[Sound class]])
{
if (fadeOut)
{
[(Sound *)soundOrName fadeOut:soundFadeDuration];
}
else
{
[(Sound *)soundOrName stop];
}
//added to fix error nsarray-was-mutated-while-being-enumerated
NSArray *tempArray = [currentSounds copy];
for(id obj in tempArray) {
//It's safe to remove objects from yourArray here.
NSLog(@"removing objects");
}
[tempArray release];
//[currentSounds removeObject:soundOrName]; //OLD CODE
return;
}
if ([[soundOrName pathExtension] isEqualToString:@""])
{
soundOrName = [soundOrName stringByAppendingPathExtension:@"caf"];
}
for (Sound *sound in [currentSounds reverseObjectEnumerator])
{
if ([sound.name isEqualToString:soundOrName] || [[sound.url path] isEqualToString:soundOrName])
{
if (fadeOut)
{
[sound fadeOut:soundFadeDuration];
}
else
{
[sound stop];
}
[currentSounds removeObject:sound];
}
}
}
Thanks for your effort.
When I installed on iPad2 of 8.1.1 there is no sound.
Thanks
For some songs i am not able to play. Getting one error message if i pass the error in this method - (Sound *)initWithContentsOfURL:(NSURL *)URL. and the error is " Error Domain=NSOSStatusErrorDomain Code=1685348671 "The operation couldn’t be completed. (OSStatus error 1685348671.)"". I am using MAC osx 10.7 and X-code 4.6.3. and the same project is working fine in MAC OSX 10.8.
example sound URL here : http://stream7.cache70.vcdn.vn/fsfsdfdsfdserwrwq3/605024dfabd67716e0bedd538d9b29ba/5567f356/2015/04/25/1/6/167fc5d627166e755e745e9f5941f40e.mp3
I Can not play this !
Hi,
I want to play a theme music on my iOS game using the following : [[SoundManager sharedManager] playMusic:kThemeSound looping:YES];
It is working well except that there is a gap (a small silence) when the sound is looping. I tried the sound in iTunes, there is no gap when looping.
Is there a way to fix this ?
Thanks,
Martin
I am using below function to play sound but if in background music on iPhone playing some songs. Then sound stops music, which is bad user experience.
[[SoundManager sharedManager] playSound:SOUND_SWIPE looping:NO];
Hi:
I download your code to do Playing background audio function. But I find a bug, when I set
[SoundManager sharedManager].allowsBackgroundMusic = YES;
But enter the background, the sound will stop play.
I search some article to solve this problem.You can refer to following articles.
How to handle background audio playing while iOS device is locked or on another application
IOS: Play sound in while app in background
I found your bug code:
- (void)setAllowsBackgroundMusic:(BOOL)allow
{
if (_allowsBackgroundMusic != allow)
{
#if TARGET_OS_IPHONE
_allowsBackgroundMusic = allow;
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:allow? AVAudioSessionCategorySoloAmbient: AVAudioSessionCategorySoloAmbient error:NULL];
#endif
}
}
You should fix as follow:
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:allow? AVAudioSessionCategoryPlayback: AVAudioSessionCategorySoloAmbient error:NULL];
and in the plist file, add Required background modes key.
When i make the playing screen, i register the remote control event, i tap on the home to send app the back ground lock the screen.
Now i tap to Home, i can see the control button on the screen, when i tap to those button, the it doesn't raise the event: - (void)remoteControlReceivedWithEvent:(UIEvent *)event
{}
is there any easy way to add a pause functionality to PlayMusic?
It can be sometimes essential to be able to pause a music that's playing and resume it later on at the same timing we paused it.
Hello nick,
any chance for a pause functionality (or a clue on how to do it)?
or am i failling at finding a way to do so?
many thnx for the awesome job!
This is a great library, thanks! I'm trying to implement a button to toggle all sound effects on/off. I've subclassed SoundManager and called it SoundEffects. However, calling this line doesn't appear to work:
NSInteger volume = [defaults boolForKey:PlayGameSounds] ? 1 : 0;
[SoundEffects sharedManager].soundVolume = volume;
I've stepped through and checked, and the volume is being set to 0. However all sound effects still play. Am I doing something wrong? Could be a subclassing issue?
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.