GithubHelp home page GithubHelp logo

edison9888 / shsoundplay Goto Github PK

View Code? Open in Web Editor NEW

This project forked from icodingboyy/shsoundplay

0.0 1.0 0.0 696 KB

一个摘自MCSoundBoard的音频管理类

License: MIT License

Objective-C 100.00%

shsoundplay's Introduction

SHSoundPlay

Goal of the project

Create a singleton class to make playing audio extremely within an iOS app simpler.

License

This code is available under the MIT license.

Installation

  1. Drag files from the Classes folder to your project;
  2. Add AudioToolbox and AVFoundation frameworks;
  3. #import "SHSoundPlay.h" wherever you want to use it.

Usage

Here's how you initialize and play a "short sound" (30s or shorter .caf, .air or .wav snippets):

	[SHSoundPlay addSoundAtPath:[[NSBundle mainBundle] pathForResource:@"ding.wav" ofType:nil] forKey:@"ding"];

	[SHSoundPlay playSoundForKey:@"ding"];

For longer AAC, MP3 and ALAC (Apple Lossless) audio, use:

    [SHSoundPlay addAudioAtPath:[[NSBundle mainBundle] pathForResource:@"play.mp3" ofType:nil] forKey:@"play"];
    
    [SHSoundPlay playAudioForKey:@"play"];

For a nice fede in effect, you can use

	[SHSoundPlay playAudioForKey:@"play" fadeInInterval:2.0];

Similar metods are available for stopping and pausing the audio:

	+ (void)stopAudioForKey:(id)key fadeOutInterval:(NSTimeInterval)fadeOutInterval;
	+ (void)stopAudioForKey:(id)key;
	
	+ (void)pauseAudioForKey:(id)key fadeOutInterval:(NSTimeInterval)fadeOutInterval;
	+ (void)pauseAudioForKey:(id)key;

For longer audio, this class uses AVAudioPlayer and, if you need to set volume, number of loops and so on, you can get access to the underlying player by calling:

    AVAudioPlayer *player = [SHSoundPlay audioPlayerForKey:@"play"];
    player.numberOfLoops = -1;  // Endless looping

shsoundplay's People

Contributors

icodingboyy avatar

Watchers

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