avaudioplayer

Resume background audio after AVAudioPlayer is paused

纵然是瞬间 提交于 2019-12-05 06:17:38
问题 I've developed an iPhone application that allows other apps to play audio in the background. To achieve this, I initialize my audio session like this: [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; At some point in my application I provide an audio player to play some files stored in CoreData with AVAudioPlayer. When the user hits the play button, the background audio should be paused. When the player has finished or is paused, the background audio

Play one instance of AVAudioPlayer in the background

有些话、适合烂在心里 提交于 2019-12-05 02:55:54
问题 I have several instances of AVAudioPlayer in my app (in separate classes). I have added multi-tasking capabilities to one instance but all audio now plays in the background. I added the 'App plays audio' key to my plist and: [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; [[AVAudioSession sharedInstance] setActive: YES error: nil]; to my class. How can I target this code to only 1 instance of AVAudioPlayer? 回答1: The only way around this I could find was

How to tell the MPNowPlayingInfoCenter wether or not the music is playing or paused?

佐手、 提交于 2019-12-05 01:38:47
I can't seem to make iOS show the correct play / pause button in the remote audio controls. I do receive the remote control events and set all values of the nowPlayingInfo dictionary. Everything works fine and I even see a cover photo on the lock screen. Except the pause/play button. It always looks like pause even if my AVAudioPlayer is playing. It sends a pause event regardless of playback state. How can I notify iOS that AVAudioPlayer is paused and that it should now show a play button in the remote control buttons bar? Jan Pittner Make sure that you're setting the

AVAudioPlayer preloaded sound leaks from memory

蓝咒 提交于 2019-12-05 00:37:59
I have an AVAudioPlayer instance that loads sound in memory with audioPlayer.prepareToPlay() , and then after a few start playing it. I have a problem that in approximately ten minutes after entering background, it leaks from memory and I is not being prepared. After that fed hours, I don't have an ability to run prepareToPlay() again. How to leave that preloaded sound in memory for a long term? I am preparing sound to play in applicationDidFinishLaunchingWithOptions method: let dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) dispatch_async(dispatchQueue, {[weak

Audio Session “Ducking” Broken in iOS 4…?

怎甘沉沦 提交于 2019-12-04 22:03:00
问题 I've an app which uses the MPAudioPlayerController to access the iPod music library, and an AVAudioPlayer to overlay audio on top of the music. I've used this documentation as a guide. Specifically: Finally, you can enhance a category to automatically lower the volume of other audio when your audio is playing. This could be used, for example, in an exercise application. Say the user is exercising along to their iPod when your application wants to overlay a verbal message—for instance, “You’ve

Reusing an AVAudioPlayer for a different sound

ぃ、小莉子 提交于 2019-12-04 20:04:13
问题 I have an instance of AVAudioPlayer that will play several sounds. Is there a way to provide an AVAudioPlayer instance with a new sound, or do I have to create a new instance with initWithData:? 回答1: Reusing objects is usually a bad idea, generally try to have your objects as short-lived as possible. This reduces the number of possible states of your code and makes reasoning about it easier. (“Where did this value come from? Maybe it’s a leftover from the previous instance usage?” Yuck.) Only

iPhone AVAudioPlayer app freeze on first play

我与影子孤独终老i 提交于 2019-12-04 16:57:43
I'm using AVAudioPlayer from iOS SDK for playing short sounds on each click in tableView rows. I have manually made @selector on button in each row that fires up method playSound:(id)receiver {} . From receiver I get sound url so I can play it up. This method looks like that: - (void)playSound:(id)sender { [audioPlayer prepareToPlay]; UIButton *audioButton = (UIButton *)sender; [audioButton setImage:[UIImage imageNamed:@"sound_preview.png"] forState:UIControlStateNormal]; NSString *soundUrl = [[listOfItems objectForKey:[NSString stringWithFormat:@"%i",currentPlayingIndex]] objectForKey:@"sound

Record Video and play audio at same time ios

限于喜欢 提交于 2019-12-04 16:09:21
问题 I want to record video and play audio simultaneously. when start recording video, preloaded audio start play and when stop video recording, audio also stops playing. I tried to record Video by using third party library " SwiftyCam " (https://github.com/Awalz/SwiftyCam) and start playing audio in delegate method when start writes video recording file. main ViewCOntroller code is below : override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) var temp = Data() let

How to Play system beep sound programatically in iPhone?Is it possible to play system sound without adding it to bundle resources

ε祈祈猫儿з 提交于 2019-12-04 13:30:08
问题 Is it possible to play system beep alert sound.I do not want to add the sound file to my resource bundle and i want to access the apple system sounds and play it wherever needed. 回答1: Try this AudioServicesPlaySystemSound(1103); to vibrate AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); For list of sounds http://iphonedevwiki.net/index.php/AudioServices 来源: https://stackoverflow.com/questions/18711983/how-to-play-system-beep-sound-programatically-in-iphoneis-it-possible-to-play-s

How to Make and Play A Procedurally Generated Chirp Sound

主宰稳场 提交于 2019-12-04 13:07:53
问题 My goal is to create a "Chirper" class. A chirper should be able to emit a procedurally generated chirp sound. The specific idea is that the chirp must be procedurally generated, not a prerecorded sound played back. What is the simplest way to achieve a procedurally generated chirp sound on the iPhone? 回答1: You can do it with a sine wave as you said, which you would define using the sin functions. Create a buffer as long as you want the sound in samples, such as: // 1 second chirp float