Giter Site home page Giter Site logo

azsoundmanager's Introduction

##Intro

AZSoundManager

AZSoundManager is a simple tool for playing sound and music in iOS apps.

##Installation

To use the AZSoundManager:

  1. Just drag the class files into your project:

    AZSoundManager.h AZSoundManager.m AZSoundItem.h AZSoundItem.m

  2. Add the AVFoundation framework.

##Classes

The AZSoundManager package defines two classes: AZSoundManager and AZSoundItem.

###AZSoundItem properties

@property (nonatomic, readonly) NSString *name;

The name of the item.

@property (nonatomic, readonly) NSURL *URL;

The absolute URL of the sound file.

@property (nonatomic, readonly) NSTimeInterval duration;

The duration (in seconds) of the sound file.

@property (nonatomic, readonly) NSTimeInterval currentTime;

The current time offset (in seconds) of the sound file.

@property (nonatomic, readonly) NSString *title;

The title from metadata of item.

@property (nonatomic, readonly) NSString *album;

The album name from metadata of item.

@property (nonatomic, readonly) NSString *artist;

The artist name from metadata of item.

@property (nonatomic, readonly) UIImage *artwork;

The artwork image from metadata of item.

###AZSoundItem creation

+ (instancetype)soundItemWithContentsOfFile:(NSString*)path;
- (instancetype)initWithContentsOfFile:(NSString*)path;
+ (instancetype)soundItemWithContentsOfURL:(NSURL*)URL;
- (instancetype)initWithContentsOfURL:(NSURL*)URL;

These methods create a new AZSoundItem instance from a file path or URL.

###AZSoundManager properties

@property (nonatomic, readonly) AZSoundStatus status;

The status of audio player.

@property (nonatomic, readonly) AZSoundItem *currentItem;

The current item of audio player.

@property (nonatomic, assign) float volume;

The sound volume. Should be in the range 0 - 1.

##Usage

###Playing a sound

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"mp3"];
AZSoundItem *item = [AZSoundItem soundItemWithContentsOfFile:filePath];

[[AZSoundManager sharedManager] playSoundItem:item];

###Preloading a sound

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"mp3"];
AZSoundItem *item = [AZSoundItem soundItemWithContentsOfFile:filePath];

[[AZSoundManager sharedManager] preloadSoundItem:item];
...
[[AZSoundManager sharedManager] play];

###Playing actions

- (void)play;
- (void)pause;
- (void)stop;
- (void)restart;
- (void)playAtSecond:(NSTimeInterval)second;

###Get actual info about playing item

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"mp3"];
AZSoundItem *item = [AZSoundItem soundItemWithContentsOfFile:filePath];

[[AZSoundManager sharedManager] playSoundItem:item];

[[AZSoundManager sharedManager] getItemInfoWithProgressBlock:^(AZSoundItem *item) {
    NSLog(@"Item duration: %ld - current time: %ld", (long)item.duration, (long)item.currentTime);
} completionBlock:^{
    NSLog(@"finish playing");
}];

License

AZSoundManager is released under the MIT license. See LICENSE for details.

azsoundmanager's People

Contributors

zzzunov avatar

Stargazers

MohsinAli avatar

Watchers

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