avaudioplayer

Recording audio in mp3 format in an iPhone app

谁都会走 提交于 2019-12-17 18:24:45
问题 I am developing an iPhone app which records the audio in .wav format. Here is the code: NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc]init]; [recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey]; [recordSetting setValue:[NSNumber numberWithFloat:11025.0] forKey:AVSampleRateKey]; [recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey]; [recordSetting setValue:[NSNumber numberWithInt:16] forKey

iphone: playing audio playlist in the background?

情到浓时终转凉″ 提交于 2019-12-17 17:53:03
问题 I'm trying to play sequence of audio files in the background using AVAudioPlayer. When the app is not in the background it plays well, but when the app goes to the background it won't play the second song. Here is my code: -(void)playAudio:(NSString *)path{ NSURL *url = [NSURL fileURLWithPath:path]; NSError *error; AVAudioPlayer *ap = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; [

Re-Assigning instance of AVAudioPlayer in iOS13 leads to BAD_ACCESS runtime error

蹲街弑〆低调 提交于 2019-12-17 16:48:35
问题 Hey guys , unfortunately I stuck and after trying a lot of things the last three days , I have to ask for help here. I have an app, that is for many years in the AppStore and runs without any crashes (last deployment target iOS 12.4). I have some code for playing a sound on certain events in the app. Now I tried to upgrade my app for iOS 13 and without changing any code related to that “playSound” thing, I always get this runtime error , when testing on a real device . Does not happen on

Get AVAudioPlayer to play multiple sounds at a time

只谈情不闲聊 提交于 2019-12-17 15:37:36
问题 I'm trying to get multiple sounds files to play on an AVAudioPlayer instance, however when one sound plays, the other stops. I can't get more than one sound to play at a time. Here is my code: import AVFoundation class GSAudio{ static var instance: GSAudio! var soundFileNameURL: NSURL = NSURL() var soundFileName = "" var soundPlay = AVAudioPlayer() func playSound (soundFile: String){ GSAudio.instance = self soundFileName = soundFile soundFileNameURL = NSURL(fileURLWithPath: NSBundle

Is it possible to test iOS4 multitasking/background music playing on the simulator?

一世执手 提交于 2019-12-17 11:03:21
问题 I have added the UIBackgroundModes property in Info.plist to have an array entry of " audio " and have added the call to setup the audio session: [session setCategory: AVAudioSessionCategoryPlayback error: &error]; . However, the only test device I have is the iPod Touch 2G which doesn't support multitasking. I've tried the simulator but the music stops playing when I switch to Safari. But when I switch back to my app, the song continues playing to a farther location than when I left the app.

Is it possible to test iOS4 multitasking/background music playing on the simulator?

为君一笑 提交于 2019-12-17 11:01:23
问题 I have added the UIBackgroundModes property in Info.plist to have an array entry of " audio " and have added the call to setup the audio session: [session setCategory: AVAudioSessionCategoryPlayback error: &error]; . However, the only test device I have is the iPod Touch 2G which doesn't support multitasking. I've tried the simulator but the music stops playing when I switch to Safari. But when I switch back to my app, the song continues playing to a farther location than when I left the app.

How to record and play sound in iPhone app?

眉间皱痕 提交于 2019-12-17 10:34:24
问题 I tried using AVAudioSession and AVAudioPlayer to record and play sounds respectively but the sound volume is very low. I tried putting volume value of AVAudioPlayer to 1.0 and more but didnt help much. What could be my other options to record sound which can be loud enough to play back? 回答1: This code should be useful for you: #import <AudioToolbox/AudioServices.h> UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker; AudioSessionSetProperty (kAudioSessionProperty

Slow start for AVAudioPlayer the first time a sound is played

人走茶凉 提交于 2019-12-17 10:18:57
问题 I'm trying to eliminate startup lag when playing a (very short -- less than 2 seconds) audio file via AVAudioPlayer on the iPhone. First, the code: NSString *audioFile = [NSString stringWithFormat:@"%@/%@.caf", [[NSBundle mainBundle] resourcePath], @"audiofile"]; NSData *audioData = [NSData dataWithContentsOfMappedFile:audioFile]; NSError *err; AVAudioPlayer *audioPlayer = [(AVAudioPlayer*)[AVAudioPlayer alloc] initWithData:audioData error:&err]; audioPlayer.delegate = self; [audioPlayer play

AVAudioPlayer: How to Change the Playback Speed of Audio?

你离开我真会死。 提交于 2019-12-17 09:01:36
问题 I want to control the playback speed of audio in AVAudioplayer . Is this possible? If so, how would you do it? 回答1: Now it is possible to change the playback speed. Sample code: player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&err]; player.volume = 0.4f; player.enableRate = YES; //<-- [player prepareToPlay]; [player setNumberOfLoops:0]; player.rate = 2.0f; //<-- Playback Speed [player play]; enableRate is set to YES and you can change it. See more in

AVAudioPlayer: How to Change the Playback Speed of Audio?

纵饮孤独 提交于 2019-12-17 09:00:03
问题 I want to control the playback speed of audio in AVAudioplayer . Is this possible? If so, how would you do it? 回答1: Now it is possible to change the playback speed. Sample code: player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&err]; player.volume = 0.4f; player.enableRate = YES; //<-- [player prepareToPlay]; [player setNumberOfLoops:0]; player.rate = 2.0f; //<-- Playback Speed [player play]; enableRate is set to YES and you can change it. See more in