Coder Social home page Coder Social logo

nicklockwood / soundmanager Goto Github PK

View Code? Open in Web Editor NEW
631.0 631.0 132.0 966 KB

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

Objective-C 100.00%

soundmanager's People

Contributors

nicklockwood avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

soundmanager's Issues

There's a gap when playing a music with the loop option activated

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

The SoundManager class needs a prefix

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.

Music stops after receiving phone-call

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

SoundManager Crashing iOS Simulator

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]];

Stack Image:
screenshot 2015-07-31 07 02 09

Not able to play the song

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.

Pause possibility

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!

support for caching

Local disk caching,
user only needs to stream a file once and after that it can be played from a local cache

no Pause Music functionality in SoundManager

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.

Stopped music starts up again on pushed modal viewController

I've got a music loop on the main viewController with a sound button to control turning the music on/off;

  • (IBAction)controlMusic:(id)sender {
    if ([SoundManager sharedManager].playingMusic)
    {
    [[SoundManager sharedManager] stopMusic];
    }
    else
    {
    [self playMusic];
    }
    }

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?

nsarray-was-mutated-while-being-enumerated

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];
    }
    }
    }

Cann't control music int the device lock screen.

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
{}

no sound on ios 8.1.1

Thanks for your effort.

When I installed on iPad2 of 8.1.1 there is no sound.
Thanks

Play Sound stops music if songs are playing

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];

Setting soundVolume to 0 doesn't appear to work

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?

No sound on some devices

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.

Adjust Pitch Function

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 ...".

Cannot stop sound(s) in Mac OS

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

Playing background audio doesn't work

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.