avaudioplayer

How to implement AVAudioPlayer Inside Singleton Method?

孤街醉人 提交于 2019-12-22 12:31:33
问题 This is my code : class SomeAudioManager: NSObject { class var sharedInstance: SomeAudioManager{ struct Static { static var onceToken: dispatch_once_t = 0 static var instance: SomeAudioManager? = nil } dispatch_once(&Static.onceToken) { Static.instance = SomeAudioManager() } return Static.instance! } func audioView(songname: NSString,format: NSString) { let audioPlayer:ava audioPlayer=try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(songname,

Converting NSData back to Audio File

纵然是瞬间 提交于 2019-12-22 12:16:31
问题 i have converted my .caf audio file to NSData object using the following line of code: NSData *audioData = [NSData dataWithContentsOfFile:[MyRecorderFilePathURL path] options: 0 error:&err]; I am doing so to upload the binary object to a server through a web service. How do i convert audioData back to a .caf file which can be played using AVAudioPlayer ? 回答1: AVAudioPlayer has a method for playing sound from NSData object . You can use - (id)initWithData:(NSData *)data error:(NSError **

Cannot Control Volume of AVAudioPlayer via Hardware Buttons when AudioSessionActive is NO

五迷三道 提交于 2019-12-22 09:33:49
问题 I'm building a turn-by-turn navigation app that plays periodic, short clips of sound. Sound should play regardless of whether the screen is locked, should mix with other music playing, and should make other music duck when this audio plays. Apple discusses the turn-by-turn use case in detail in the "WWDC 2010 session 412 Audio Development for iPhone OS part 1" video at minute 29:20. The implementation works great, but there is one problem - when the app is running, pressing the hardware

OpenAL vs AVAudioPlayer vs other techniques for playing sounds

巧了我就是萌 提交于 2019-12-22 08:51:53
问题 I know that OpenAL is fast library but it doesn't support any compressed audio format and it's not so easy to use... AVAudioPlayer is not so fast, but supports wide range file formats, as well as compressed formats like mp3. Also there is an SKAction class which can play a sound, as well as SystemSoundID... I have few questions: What would be a preferred way/player/technique to play : sound effects(multiple at the time)? sound effects which can be sometimes repeated after small time delay

MPMediaItem not playing in AVAudioPlayer using MPMediaItemPropertyAssetURL

随声附和 提交于 2019-12-22 08:16:42
问题 I have this code, to find and play a MPMediaItem: MPMediaPropertyPredicate *predicate = [MPMediaPropertyPredicate predicateWithValue:self.persistentIDOfSongToPlay forProperty:MPMediaItemPropertyPersistentID comparisonType:MPMediaPredicateComparisonContains]; NSSet *predicateSet = [NSSet setWithObject:predicate]; MPMediaQuery *searchQuery = [[MPMediaQuery alloc] initWithFilterPredicates:predicateSet]; NSArray *queryResults = [searchQuery items]; NSLog(@"count: %i", queryResults.count);

How to perform operations when playing sound in iPhone?

痞子三分冷 提交于 2019-12-22 06:59:38
问题 I play a MP3 in my iPhone app using AVAudioPlayer; i need to perform some operations at certain times (say 30th seconds, 1 minute); is there a way to invoke callback functions based on mp3 playing time? 回答1: I believe the best solution is to start an NSTimer as you start the AVAudioPlayer playing. You could set the timer to fire every half second or so. Then each time your timer fires, look at the currentTime property on your audio player. In order to do something at certain intervals, I'd

Playing audio file while recording video in iOS

一个人想着一个人 提交于 2019-12-22 05:52:50
问题 I want to play audio file while recording with camera. I used AVAudioPlayer for playing audio and AVCamCaptureManager for recording. But when audio starts to play, preview screen is freezing. What should i do? Thanks for your helping. Here is the code. (I'm working on AVCam example.) This is preview part. if ([self captureManager] == nil) { AVCamCaptureManager *manager = [[AVCamCaptureManager alloc] init]; [self setCaptureManager:manager]; [[self captureManager] setDelegate:self]; if ([[self

AVAudioPlayer resetting currently playing sound and playing it from beginning

一世执手 提交于 2019-12-22 01:42:29
问题 I'm having an issue using AVAudioPlayer where I want to reset a player if it's currently playing and have it play again. I try the following with no luck: The sound plays once but then the second time i select the button it stops the sound, the third time starts the sound up again. //Stop the player and restart it if (player.playing) { NSLog(@"Reset sound: %@", selectedSound); [player stop]; [player play]; } else { NSLog(@"playSound: %@", selectedSound); [player play]; } I've also tried using

AVAudioPlayer rate change introduces artifacts/distortion

风格不统一 提交于 2019-12-22 01:01:22
问题 I am trying to change the rate of a sound file played through AVAudioPlayer. It works, but there are significant artifacts, especially when I slow down the rate. I'm happy that the rate change maintains the same pitch but it seems to have trouble, especially with sustained notes. It seemed like the rate change was working pretty well until I tried it with higher quality sounds that had been equalized, compressed, and mastered. I'm concerned that the AVAudioPlayer rate change can't deal with

AudioServicesPlaySystemSound muted on simulator xCode 6 GM

橙三吉。 提交于 2019-12-21 17:24:04
问题 I run the following code on simulator and I don't get any sound: NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"pageflip" ofType:@"mp3"]; NSURL *soundUrl = [NSURL fileURLWithPath:soundPath]; AudioServicesCreateSystemSoundID((__bridge CFURLRef) soundUrl, &_soundEffect); AudioServicesPlaySystemSound(_soundEffect); The code has been successfully tested on xCode 5 and iOS 7. Libraries imported as required. I've logged the soundPath and it returns the correct location on the