Skip to content

Instantly share code, notes, and snippets.

@caioluders
Created May 25, 2015 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caioluders/e6f6af13a953ff0a2b10 to your computer and use it in GitHub Desktop.
Save caioluders/e6f6af13a953ff0a2b10 to your computer and use it in GitHub Desktop.
iOS Objective-c Audio Tutorial
//
// ViewController.m
// Audio Tuto
//
// Created by Caio Araújo on 20/05/15.
// Copyright (c) 2015 Caio Araújo. All rights reserved.
//
#import "ViewController.h"
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>
@interface ViewController ()
@property ( strong , nonatomic ) AVAudioPlayer *player ;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString *soundPath = [NSString stringWithFormat:@"%@/mysound.mp3" , [[NSBundle mainBundle] resourcePath]] ;
NSURL *soundUrl = [NSURL fileURLWithPath:soundPath] ;
_player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil ] ;
_player.numberOfLoops = -1 ;
[_player prepareToPlay] ;
[_player play] ;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment