GithubHelp home page GithubHelp logo

nsakhan / amgsoundmanager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from albertmontserrat/amgsoundmanager

0.0 2.0 0.0 1.29 MB

An awesome and simple singleton sound manager for iOS in Objective C, where you can play audio in different lines, control each audio or the entire line, change volume in live of a single audio or a group of audios, etc. All with one simple line of code!

License: MIT License

Ruby 9.99% Objective-C 61.18% C 2.87% Shell 25.96%

amgsoundmanager's Introduction

AMGSoundManager

[![CI Status](http://img.shields.io/travis/Albert M/AMGSoundManager.svg?style=flat)](https://travis-ci.org/Albert M/AMGSoundManager) Version License Platform

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

AMGSoundManager requires ios 6.0 and above.

Installation

AMGSoundManager is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "AMGSoundManager"

How it works

AMGSoundManager works as a sigleton instance that manages all audios that are playing across differents screens.

To create the singleton just write:

[AMGSoundManager sharedManager]

To play an audio, AMGSoundManager provides multiple options:

-(BOOL)playAudioAtPath:(NSString *)audioPath;
-(BOOL)playAudioAtPath:(NSString *)audioPath withName:(NSString *)name;
-(BOOL)playAudioAtPath:(NSString *)audioPath withName:(NSString *)name inLine:(NSString *)line;
-(BOOL)playAudioAtPath:(NSString *)audioPath withName:(NSString *)name inLine:(NSString *)line withVolum:(float)volum;
-(BOOL)playAudioAtPath:(NSString *)audioPath withName:(NSString *)name inLine:(NSString *)line withVolum:(float)volum andRepeatCount:(int)repeatCount;

As you can see, you can simply play an audio with just it's path. But also you can specify a name, line, volume and repeat count. If repeat count is -1, the audio makes a loop.

The name is used to identify a single sound (or a group of sounds with the same file, or whatever you want) and the line is normally used to identify a kind of sounds such as sfx, voices, background sounds, etc. But it's up to you what name and line you want to put in every sound.

Then, you can stop the audios with the following methods:

-(void)stopAllAudios;
-(void)stopAllAudiosForLine:(NSString *)line;
-(void)stopAllAudiosWithoutLine;
-(void)stopAudioWithName:(NSString *)name;
-(void)stopAudioWithPath:(NSString *)path;

Also, if you want to check if an audio is currently playing you can wirte:

-(BOOL)isAudioPlayingInLine:(NSString *)line;
-(BOOL)isAudioPlayingInLine:(NSString *)line withName:(NSString *)name;

You can also pause and resume an audio:

-(void)pauseAudiosInLine:(NSString *)line;
-(void)resumeAudiosInLine:(NSString *)line;

And the most awesome feature: you can change the volume of any audio currently playing!

-(void)setVolume:(float)volum forLine:(NSString*)line;

AMGSoundManager also implements a delegate to notify when an audio has finished or has given some kind of error. With this, you can make a sequence of audios.

-(void)audioDidFinish:(NSString *)name inLine:(NSString *)line;
-(void)audioErrorOcurred:(NSString *)name inLine:(NSString *)line;

There's also an other way to know when an audio has ended using notifications:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(soundEndedNotification:) name:kSoundManagerAudioEnded object:nil];

And then:

-(void)soundEndedNotification:(NSNotification *)notification{

    NSDictionary *info = notification.userInfo;
    NSString *line = [info objectForKey:@"line"];
    NSDictionary *audio = [info objectForKey:@"info"];
    NSString *name = [audio objectForKey:@"name"];

    if([name isEqualToString:@"my_audio_name"]){
        //Do whatever
    }

}

Examples

Run a background sound:

if(![[AMGSoundManager sharedManager] isAudioPlayingInLine:@"background"]){
    [[AMGSoundManager sharedManager] playAudioAtPath:[[NSBundle mainBundle] pathForResource:@"background_music" ofType:@"mp3"]
                                            withName:@"ambient"
                                              inLine:@"background"
                                           withVolum:0.3
                                      andRepeatCount:-1];
}

To stop all audios in a line:

[[AMGSoundManager sharedManager] stopAllAudiosForLine:@"background"];

To change the volume of an audio in live:

[[AMGSoundManager sharedManager] setVolume:2.0 forLine:@"background"];

License

AMGSoundManager is available under the MIT license. See the LICENSE file for more info.

amgsoundmanager's People

Contributors

albertmontserrat avatar

Watchers

 avatar  avatar

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.