代码之家  ›  专栏  ›  技术社区  ›  Thomas Clayson

在iPhone上,AVAudioPlayer非常安静,但在iPod touch上声音足够大

  •  3
  • Thomas Clayson  · 技术社区  · 15 年前

    我有一些声音是在一个循环中播放的,因为噪音是用音频录像机记录的。

    这是我的代码:

    NSString *pathToFile = [[NSBundle mainBundle] pathForResource:@"foghornRepeat2" ofType:@"aif"];
            foghornRepeat =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:pathToFile] error:nil];
            //foghornRepeat.delegate = self;
            [foghornRepeat prepareToPlay];
    
            foghornRepeat.numberOfLoops = -1;
            [foghornRepeat setVolume:1];
    

    当声音通过麦克风注册时,它将被播放和停止。你知道为什么在iphone上会很安静吗?我的ipod touch没问题。

    我还有别的办法吗?

    谢谢 汤姆

    1 回复  |  直到 15 年前
        1
  •  4
  •   Dirk Scholten    15 年前

    可能发生的情况是,你的iphone上的音频重新路由到了电话扬声器。要确保声音从真实扬声器播放,请在播放声音效果之前使用以下代码:

       UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
     AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
    
    推荐文章