play mp3 sound

by nik 4. May 2009 04:55

//need to add: AVFoundation.framework

#import <AVFoundation/AVAudioPlayer.h> 

NSBundle *mainBundle = [NSBundle mainBundle];

NSURL *url = [NSURL fileURLWithPath:[mainBundle pathForResource:@"game" ofType:@"mp3"] isDirectory:NO];

 

AVAudioPlayer *gameSoundTrack = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];

[gameSoundTrack prepareToPlay];

[gameSoundTrack play]; 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

General

Play Sound Effect

by nik 17. March 2009 07:02

#import "SoundEffect.h"

 

// init sound

NSBundle *mainBundle = [NSBundle mainBundle];

SoundEffect *tapSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"tap_snd" ofType:@"caf"]]; 

 

 // play sound

 [tapSound play];

 

SoundEffect.m (1.13 kb)

SoundEffect.h (263.00 bytes)

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen