avaudioplayer

Best way for looping and using background sounds in iphone?

大憨熊 提交于 2019-12-11 15:08:07
问题 Lets say I am dragging my finger on screen and I have 1 second .caf sound file in my bundle. So what is the best way to play my sound file in a loop till i am dragging my fingers. And it should stop whenever I remove touches. I know touches implementation. Just post your views about using sound file. 回答1: See AVAudioPlayer class, it worked pretty well for me for similar behaviour described in your question. 回答2: This is how I did it. At the moment, I don't know of a more efficient method..

How to play NSData from Core Data in AVAudioPlayer

∥☆過路亽.° 提交于 2019-12-11 13:32:29
问题 I save mp3 file into Core Data as NSData binary data. Then I load this file with help of NSFetchedResultsController . Then I wrote following code but I got the error. How can I fix it? fatal error: unexpectedly found nil while unwrapping an Optional value var audioPlayer = AVAudioPlayer() func play() { if musicData != nil { audioPlayer = AVAudioPlayer(data: musicData, error: nil) AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil) AVAudioSession

MemoryLeak problem in following case

孤人 提交于 2019-12-11 11:46:32
问题 I am getting a memory leak when i click the play button.... I am testing with that "Leak" tool under "Run and performance tool"....on simulator I am getting that leak when i click the play button first time..... Here is my code.... -(IBAction)play { [self setPlayer]; [self playme]; } -(IBAction)stop { [self stopme]; [self releasePlayer]; } -(void)setPlayer { NSURL *file = [[NSURL alloc] initFileURLWithPath: [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"shut up.mp3"]];

How to do unlimited repetition by using AVAudioPlayer in ios

烂漫一生 提交于 2019-12-11 11:43:03
问题 In my app i am using audio. I want to play audio for unlimited time on tapping button. Is it possible? 回答1: Easiest way is to re-play the player when it reaches the end : -(void)startPlayer { NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"sound" ofType:@"mp3"]]; NSError *error; player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; player.delegate = self; if (error) { NSLog(@"Error in audioPlayer: %@", [error localizedDescription]); } else {

Massive fps drops when AVAudioPlayer ist triggered repeatedly (Sprite Kit)

蹲街弑〆低调 提交于 2019-12-11 10:48:09
问题 I am creating an iOS-Game in Sprite Kit in which you can fire a water gun. As long as the water gun is fired, a slash-sound is played. Since I implemented this feature, I have massive fps-problems when the sound effect ist triggered repeatedly with the touches-began-method. Is there any possibility to fix that issue? @property (nonatomic) AVAudioPlayer *splashSound; -(id)initWithSize:(CGSize)size { NSError *error3; NSURL *splashURL = [[NSBundle mainBundle] URLForResource:@"splash"

AVMIDIPlayer init with MusicSequence

情到浓时终转凉″ 提交于 2019-12-11 09:23:59
问题 AVMIDIPlayer has this initializer: initWithData:soundBankURL:error: This is in addition to an initializer for reading from a standard MIDI file. The data is NSData, which I assumed is in a standard MIDI file format. So, how to get that data? Well, the current way to create a MIDI sequence is the AudioToolbox MusicSequence. (AVAudioEngine even has a member of this type). MusicSequence has this converter: MusicSequenceFileCreateData ( MusicSequence inSequence, MusicSequenceFileTypeID inFileType

Audio playing in background not working in iOS Simulator

空扰寡人 提交于 2019-12-11 07:56:42
问题 I've seen lots of questions about playing audio in the background. These questions often ask why the audio plays in the background of the simulator, yet the device simply wouldn't. In my case, it's reversed. When I tested my sample app in my iPad, it worked perfectly. However, when I began testing in the simulator, it simply wouldn't continue playing in the background. Here are the codes I used: NSURL *url = [NSURL URLWithString:firstSong]; audioPlayer = [[AVAudioPlayer alloc]

How to play multiple audio files using AVAudioPlayer

荒凉一梦 提交于 2019-12-11 06:43:31
问题 In my application, I am displaying multiple images in rows and columns when i click on a image i will play corresponding sound using someName = [someName stringByAppendingFormat:@".mp3"]; [audioPlayer stop]; NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%s", [[NSBundle mainBundle] resourcePath],[someName UTF8String]]]; NSError *error; audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; audioPlayer.delegate = self; When i am clicking on the one

AudioUnit framework not found

柔情痞子 提交于 2019-12-11 06:04:30
问题 I am implementing an audio based application, in that I need to play both application audio and ipod auido. When I try to run my application I am getting an error like, ld: framework not found AudioUnit collect2: ld returned 1 exit status Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 failed with exit code 1 my view controller code is as follows, .h file: #import <UIKit/UIKit.h> #import <MediaPlayer/MediaPlayer.h> #import <AudioToolbox/AudioToolbox.h>

Why calling audioplayer.play(atTime: delay) makes no sound regardless of the value of delay

帅比萌擦擦* 提交于 2019-12-11 05:39:43
问题 Expect: When audioplayer.play(atTime: 1) is called, a timer resets to 0, and the audioplayer is played at the 1st second Reality: I tried delay = 0.000000001, 1, 100000000, but regardless, no noise would ever be played. The code was clearly executed however (because "function was called" appeared in console) Why the discrepancy? C = AVAudioPlayer() // assume other setups are done C.play(atTime: 1) print("function was called") 回答1: according to the official API Reference (translation to swift