avaudioplayer

AVAudioPlayer preloaded sound leaks from memory

最后都变了- 提交于 2019-12-06 19:02:55
问题 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

Playing sequence of sounds in background with AVAudioPlayer

寵の児 提交于 2019-12-06 15:55:45
I want to play sequence of sounds with AVAudioPlayer . All are ok in foreground, but in background I have issues. After scheduling next sound it plays in background, but initialisation of sound after next fails. How to resolve this issue? In fact, I have sequence of sounds and sequence of starting moments. When user touch button application starts play sounds. I use the following code: - (void)soundScheduleNext { NSURL * url = ...; // get url of next sound file if (soundPlayer == nil) soundPlayer = [AVAudioPlayer alloc]; soundPlayer = [soundPlayer initWithContentsOfURL:url error:nil];

Converting NSData back to Audio File

五迷三道 提交于 2019-12-06 14:10:37
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 ? AVAudioPlayer has a method for playing sound from NSData object . You can use - (id)initWithData:(NSData *)data error:(NSError **)outError method of AVAudioPlayer 来源: https://stackoverflow.com/questions/9157916/converting-nsdata-back-to-audio

Can I play a sound with vibrate using AVAudioPlayer?

社会主义新天地 提交于 2019-12-06 13:47:51
I have AVAudioPlayer playing a sound for a message alert during chat, I also want the phone to vibrate. Is it possible to do this in AVAudioPlayer or do I need to use a different method? Thanks To play a sound: NSString *source = [[NSBundle mainBundle] pathForResource:@"beep" ofType:@"mp3"]; self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:source] error:nil]; self.audioPlayer.delegate = self; self.audioPlayer.numberOfLoops = 0; self.audioPlayer.volume = 1.0; [self.audioPlayer play]; Swift 2.2 version: var source = NSBundle.mainBundle().pathForResource(

iOS - Attempting to play mp3 file fails

拜拜、爱过 提交于 2019-12-06 12:38:46
I'm trying to playback and mp3 file I retrieve from my server from my app doing the following: - (IBAction)play:(UIButton *)sender { dispatch_queue_t downloadQueue = dispatch_queue_create("audio data downloader", NULL); dispatch_async(downloadQueue, ^{ NSURL *audioURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@/%@.mp3", FONYK_FILES_URL, [self.voicenote valueForKeyPath:@"Fonyker.fonykid"], [self.voicenote valueForKeyPath:@"Voicenote.vnid"]]]; NSData *audioData = [NSData dataWithContentsOfURL:audioURL]; dispatch_async(dispatch_get_main_queue(), ^{ NSError *error = nil; AVAudioPlayer

AVAudioPlayer not playing sounds simultaneously

时光怂恿深爱的人放手 提交于 2019-12-06 11:50:27
I am trying to play a couple of sounds files at the same time for the AVAudioPlayer. I read a thread explaining how to do it @ AVAudioPlayer Help: Playing multiple sounds simultaneously, stopping them all at once, and working around Automatic Reference Counting . It seems to be a weird issue as I when i try to only play one file at a time (when self.options.on is ON), it works, but when I try creating multiple instances (the else statements) and play them nothing plays. I checked to see if the outputfile URL is correct and it is, so what is the reason that it isn't working? Thanks! - (void

iPhone AVAudioPlayer app freeze on first play

巧了我就是萌 提交于 2019-12-06 11:33:35
问题 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 =

How to implement AVAudioPlayer Inside Singleton Method?

让人想犯罪 __ 提交于 2019-12-06 10:44:47
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, ofType:format)!), fileTypeHint: AVFileTypeMPEGLayer3) audioPlayer!.delegate=self; self.audioPlayer!.play() }

How to change audio recording settings to 16Khz and 16 bit when we record audio?

早过忘川 提交于 2019-12-06 09:13:53
I have the settings shown below. I want change audio recording settings to 16Khz and 16 bit when we record audio. NSArray *dirPaths; NSString *docsDir; dirPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); docsDir = [dirPaths objectAtIndex:0]; NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"sound.wav"]; NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath]; NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:AVAudioQualityMin], AVEncoderAudioQualityKey, [NSNumber numberWithInt:16],

Audio - Jump Forward 30 Seconds

删除回忆录丶 提交于 2019-12-06 08:19:13
I've got an audio player that plays audio retrieved from Core Date. Play & pause work fine. I'm trying to implement a 'Jump Forward 30 Seconds' button and seeking any pointers as to how I would go about that. Code for my 'Play/pause' button @IBAction func playPressed(sender: AnyObject) { let play = UIImage(named: "play") let pause = UIImage(named: "pause") if audioPlayer.playing { pauseAudioPlayer() audioPlayer.playing ? "\(playButton.setImage( pause, forState: UIControlState.Normal))" : "\(playButton.setImage(play , forState: UIControlState.Normal))" }else{ playAudio() audioPlayer.playing ? "