Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone AVAudioPlayer音量低(如何从扬声器设置音量)_Iphone_Ios7_Avaudioplayer - Fatal编程技术网

Iphone AVAudioPlayer音量低(如何从扬声器设置音量)

Iphone AVAudioPlayer音量低(如何从扬声器设置音量),iphone,ios7,avaudioplayer,Iphone,Ios7,Avaudioplayer,我使用AVAudioPlayer播放声音,但播放时,音量非常低 我做了一次搜索,找到了许多关于添加会话属性或会话类别的代码,但我想知道如何使用它 -(void) playVoice: (NSString *) path { if([path isEqualToString:@""] == NO) { //Initialize the AVAudioPlayer. NSData *soundData= [NSData dataWithContents

我使用AVAudioPlayer播放声音,但播放时,音量非常低

我做了一次搜索,找到了许多关于添加会话属性或会话类别的代码,但我想知道如何使用它

-(void) playVoice: (NSString *) path
{
    if([path isEqualToString:@""] == NO)
    {
        //Initialize the AVAudioPlayer.
        NSData *soundData= [NSData dataWithContentsOfFile:path];
        NSError *error;
        audioPlayer= [[AVAudioPlayer alloc] initWithData:soundData error:&error];

        if (error)
        {
            NSLog(@"Error in audioPlayer: %@",
                  [error localizedDescription]);
        } else {
                      audioPlayer.delegate = self;
            NSLog(@"total time=%f", self.audioPlayer.currentTime);
            self.PlayStatusSlider.maximumValue= audioPlayer.duration;
            myTimer= [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(changeAudioProgress) userInfo:nil repeats:YES];
            [audioPlayer prepareToPlay];
            [audioPlayer setVolume:1.0];


            [audioPlayer play];
        }
    }else{
        //  NSLog(@"ErrorDownloading");
    }
}

- (void) configureAVAudioSession
{
    //get your app's audioSession singleton object
    AVAudioSession* session = [AVAudioSession sharedInstance];

    //error handling
    BOOL success;
    NSError* error;

    //set the audioSession category.
    //Needs to be Record or PlayAndRecord to use audioRouteOverride:

    success = [session setCategory:AVAudioSessionCategoryPlayAndRecord
                             error:&error];

    if (!success)  NSLog(@"AVAudioSession error setting category:%@",error);

    //set the audioSession override
    success = [session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker
                                         error:&error];
    if (!success)  NSLog(@"AVAudioSession error overrideOutputAudioPort:%@",error);

    //activate the audio session
    success = [session setActive:YES error:&error];
    if (!success) NSLog(@"AVAudioSession error activating: %@",error);
    else NSLog(@"audioSession active");
}

但这对我不起作用。女巫部分错了?我应该如何使用它?

您必须将音频会话设置为默认为扬声器。 对于现在遇到这个问题的任何人:

私有变量配置AudioSessionError:n错误

let audioSession = AVAudioSession.sharedInstance()

do {
  try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, with: .defaultToSpeaker)
  try audioSession.setActive(true)

 } catch let error as NSError {
   configureAudioSessionError = error
 }

声音实际上是从扬声器还是从接收器发出的?您是否在其他地方测试过该剪辑,以确保音量足够高?系统音量是否设置为适当的音量?没有(公共)方式以编程方式控制系统音量,系统音量根据AVAudioPlayer的音量进行调节,因此,这可能会导致您的输出级别低。我正在使用emulator。我在播放器上播放,音量很好,但在emulator上使用app播放时,音量很低。您应该在设备上测试这一点。模拟器的行为可能与设备不同,您可能会发现这不是问题。我认为它与模拟器无关。因为我在模拟器中运行的其他应用程序可以播放高音量的声音