Tag: avaudiosession

AvAudioSession不能在iOS7中工作?

#import "SctreamAudioViewController.h" #import <AVFoundation/AVFoundation.h> #import "SecondViewController.h" @interface SctreamAudioViewController () @property (nonatomic, strong) AVPlayer *player; @end @implementation SctreamAudioViewController #define STREAM @"http://localhost/audio.mp3" – (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. AVAudioSession *audioSession = [AVAudioSession sharedInstance]; [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:nil]; [audioSession setActive:YES error:nil]; NSURL *url = [[NSURL alloc] […]

在UILocalNotification声音比AVAudioPlayer在最大音量

为了这个问题的目的,想象我的应用程序每10秒播放一个audio剪辑。 此audio使用AVAudioPlayer播放/与设备上的iPod音乐播放器(使用低频)混合。 当应用程序被发送到后台,我安排UILocalNotification对象与audio文件引用(和没有文字),所以声音继续播放以10秒为间隔。 令我困扰的是,在iOS 6上作为通知的一部分播放的audio剪辑的音量似乎是我在应用程序中播放audio时的两倍(我将音量设置为1.0f,文档说是最大)。 所以,每隔10秒钟,应用程序就会播放声音,当您发送到背景时,与应用程序中的内容相比,现在声音非常响亮。 相关片段…应用程序启动,这里是我如何设置AVAudioSession,以启用ducking: [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; UInt32 doChangeDefaultRoute = 1; AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof (doChangeDefaultRoute), &doChangeDefaultRoute); OSStatus propertySetError = 0; UInt32 allowMixing = true; propertySetError = AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers,sizeof (allowMixing),&allowMixing); …我如何创build我的球员: – (AVAudioPlayer *)playerWithCAFFileNamed:(NSString *)fname { NSURL *u = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:fname ofType:@"caf"]]; NSData *d = [NSData dataWithContentsOfURL:u]; AVAudioPlayer *p = […]

AVAudioSession激活问题

我收到以下错误: [0x19bf89310] AVAudioSession.mm:646: – [AVAudioSession setActive:withOptions:error:]:取消激活正在运行I / O的audio会话。 在停用audio会话之前,应该停止或暂停所有I / O。 我已阅读这篇文章: iOS8 AVAudioSession setActive错误 然而,那里的解决scheme并没有解决我的问题。 这是: 小应用(游戏) audio背景音乐在AudioHelper.swift中处理 用SKActino.playSoundFile播放额外的“blip”声音 再生产 开始游戏(背景音乐开始播放) closures游戏(音乐停止) 重新开始游戏(音乐重新开始) 出现以上错误 SKAction.playSoundFile不总是工作了(有些做,有些则不) 我的audio处理代码(又名AudioHelper.swift) class AudioHelper: NSObject, AVAudioPlayerDelegate { var player : AVAudioPlayer? class var defaultHelper : AudioHelper { struct Static { static let instance : AudioHelper = AudioHelper() } return Static.instance […]

AVAudioSession Swift

我正在写一个快速的iOS应用程序,将logging用户的声音。 我在swift中编写了下面的代码,但它无法从用户请求话筒权限。 它打印的授权,但它从来没有loggingaudio,并在隐私设置窗格中不列出的应用程序。 如何在swift中请求录制权限? var session: AVAudioSession = AVAudioSession.sharedInstance() session.requestRecordPermission({(granted: Bool)-> Void in if granted { println(" granted") session.setCategory(AVAudioSessionCategoryPlayAndRecord, error: nil) session.setActive(true, error: nil) self.recorder.record() }else{ println("not granted") } })

在背地播放音乐:AVAudioSessionInterruptionNotification未被触发

我的应用程序正在播放背景。 即使我的应用程序是使用为AVAudioSessionInterruptionNotification注册的方法的背景,也可以暂停和播放 。 问题到达这个场景的步骤: 启动我的应用程序 – >从我的应用程序播放背景音乐 启动苹果的音乐应用程序和播放。 AVAudioSessionInterruptionNotification激发 。 当我暂停音乐应用程序或杀死音乐应用程序。 AVAudioSessionInterruptionNotification不会被解雇 代码:我在appdelegate做这个。 didfinishlaunching NSError *sessionError = nil; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&sessionError]; [[AVAudioSession sharedInstance] setActive:YES error: nil]; self.player = [[AVQueuePlayer alloc] initWithURL:[NSURL URLWithString:@"http://someurl.com:8040/;stream.mp3"]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAudioSessionEvent:) name:AVAudioSessionInterruptionNotification object:nil]; – (void) onAudioSessionEvent: (NSNotification *) notification { //Check the type of notification, especially if you are […]

如何解决iOS中的AVCaptureSession v AVAudioSession冲突?

我试图在视图控制器中运行一个AVCaptureSession,但在同一个,我也从一个库使用AVAudioSession调用一个函数。 我似乎无法从debugging器中获得更多的信息,除了当我调用这个特定的库函数时崩溃。 该库是libpd: https://github.com/libpd 它调用AVAudioSession作为sharedInstance。 我把libpd称为: [self.audioController configurePlaybackWithSampleRate:44100 numberChannels:2 inputEnabled:YES mixingEnabled:YES] 所以混合启用,但以防万一,我已经重新编译它,所以当它进入,我做: UInt32 doSetProperty = 1; AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(doSetProperty), &doSetProperty); 但是,没有运气。 将调用libpd移到视图控制器中的viewWillAppear也没有工作。 但是,如果我将调用libpd的代码从viewcontroller中取出,并将其放入didFinishLaunchingWithOptions中的应用程序委托中,则它将启动得很好,两个会话似乎并不会崩溃。 我是否缺less关于AVCaptureSession和混合的东西? 我如何去两个会议共存? 我没有使用AVCapture捕捉audio,只有相机input,所以我不应该能够以某种方式进行?

在iOS7和更高版本的接收器和扬声器之间切换audio输出?

我有一个audio播放器,当接近传感器通知1时,可以select将audio输出从扬声器切换到接收器/听筒(不pipe耳机是否连接)。以下是我的代码。 – (void) switchAudioOutput:(NSString*)output{ AVAudioSession* audioSession = [AVAudioSession sharedInstance]; BOOL success; NSError* error; if([output isEqualToString:keAudioOutputReciever]){ //Force current audio out through reciever //set the audioSession override success = [audioSession overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:&error]; if (!success) NSLog(@"AVAudioSession error overrideOutputAudioPort:%@",error); //activate the audio session success = [audioSession setActive:YES error:&error]; if (!success) NSLog(@"AVAudioSession error activating: %@",error); else NSLog(@"AVAudioSession active with override: […]

AVAudioSessionManager availableInputs“端口iPhone麦克风的未知选定数据源”

我已经注意到我的控制台日志中的这个错误一段时间。 虽然它不影响我的应用程序的执行,但我发现它真的很烦人。 于是,我开始追踪这个错误来自哪里。 事实certificate,当我打电话availableInputs NSArray *inputs = [[AVAudioSession sharedInstance] availableInputs]; 它会给我的日志消息: ERROR: [0x3d61318c] AVAudioSessionPortImpl.mm:50: ValidateRequiredFields: Unknown selected data source for Port iPhone Microphone (type: MicrophoneBuiltIn) 我试图打印input Printing description of inputs: <__NSArrayI 0x188c4610>( <AVAudioSessionPortDescription: 0x188c4580, type = MicrophoneBuiltIn; name = iPhone Microphone; UID = Built-In Microphone; selectedDataSource = (null)>, <AVAudioSessionPortDescription: 0x18835d90, type = BluetoothHFP; name = […]

setPreferredHardwareSampleRate不起作用

我正在使用可以在这里find的代码。 我试图改变采样率使用: [[AVAudioSession sharedInstance] setPreferredHardwareSampleRate:SAMPLE_RATE error:nil]; 在SoundRecoder.m文件的init函数里面。 (SAMPLE_RATE是16000.0) 当我检查文件时,它似乎仍然是元数据说采样率是44100,我也试过使用(如这里所build议的): AudioSessionSetProperty ( kAudioSessionProperty_PreferredHardwareSampleRate ,sizeof(F64sampleRate) , &F64sampleRate ); 当F64sampleRate是16000但仍然相同的故障。 设备是否可以select采样率(它被称为首选),有什么办法可以设置它吗? 任何想法解决这个代码问题将有所帮助。 谢谢! 更新:我认为这个问题与队列本身有关。 因为采样率有44100。 这是我的整个代码基于我已经链接到更早的代码: #import "SoundRecoder.h" #import <AVFoundation/AVFoundation.h> #import <FLAC/all.h> #define SAMPLE_RATE 16000.0 // Sample rate I want the Flac file to have @interface SoundRecoder () <AVCaptureAudioDataOutputSampleBufferDelegate>{ AVCaptureSession *_session; int _frameIndex; BOOL _ready; int _sampleRate; int […]

录制video/audio时播放系统声音

当我开始录制video时,我正尝试播放苹果所需的“哔哔”声。 我已经通过SO和其他来源发现,当audioinput没有进行某些configuration时,您将无法播放声音。 这是我的configuration方法的尝试: private void SetupAudio() { beepSound = AssetBank.GetSystemSoundWav("video_record", "video_beep"); AudioSession.Initialize(); AudioSession.Interrupted += delegate { Console.WriteLine("Interrupted handler"); }; AudioSession.Category = AudioSessionCategory.PlayAndRecord; AudioSession.OverrideCategoryMixWithOthers = true; NSError err; AVAudioSession.SharedInstance().SetActive(true, out err); } 这里是我设置logging会话的代码: public void SetupVideoCaptureSession(AVCaptureDevicePosition position) { // Setup devices foreach (var device in AVCaptureDevice.Devices) { if (device.HasMediaType(AVMediaType.Video)) { if (device.Position == AVCaptureDevicePosition.Front) { frontCam […]