Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.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 如何在iOS中以最大音量播放声音文件,而无需更改声音指示器_Iphone_Ios_Audio_Volume_Max - Fatal编程技术网

Iphone 如何在iOS中以最大音量播放声音文件,而无需更改声音指示器

Iphone 如何在iOS中以最大音量播放声音文件,而无需更改声音指示器,iphone,ios,audio,volume,max,Iphone,Ios,Audio,Volume,Max,在我的应用程序中,我需要播放从0到最大系统音量的声音(这是一个报警应用程序) 我目前使用AVAudioPlayer播放声音,并使用MPMusicPlayerController在报警期间最大化设备音量 MPMusicPlayerController.applicationMusicPlayer.volume = 1.0; NSString *fileName = [NSString stringWithFormat:alarm.sound]; fileName = [fileName str

在我的应用程序中,我需要播放从0到最大系统音量的声音(这是一个报警应用程序)

我目前使用
AVAudioPlayer
播放声音,并使用
MPMusicPlayerController
在报警期间最大化设备音量

MPMusicPlayerController.applicationMusicPlayer.volume = 1.0;


NSString *fileName = [NSString stringWithFormat:alarm.sound];
fileName = [fileName stringByDeletingPathExtension];

NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"aifc"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];

audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
audioPlayer.volume = 0.0;
audioPlayer.numberOfLoops = -1;

[audioPlayer prepareToPlay];

audioPlayer.play;
然后我安排了一个定时器来增加音量

timer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                         target:self
                                       selector:@selector(pollTimeForGradualVolumeIncrease)
                                       userInfo:nil repeats:YES];
//逐渐增加音量

- (void)pollTimeForGradualVolumeIncrease
{
    timerSecond += 1;

    if (audioPlayer.volume < 1.0 && timerSecond % 1 == 0)
    {
        [audioPlayer setVolume:audioPlayer.volume + 0.02];
        UISlider *slider = volumeSliderView.subviews[0];
        [slider setValue:1.0 animated:NO];
    }
    else if (audioPlayer.volume >= 1.0)
    {
        timerSecond = 0;
        timer.invalidate;
        timer = nil;
    }
}
-(无效)pollTimeForGradualVolumeIncrease
{
timerSecond+=1;
如果(audioPlayer.volume<1.0&&timerSecond%1==0)
{
[audioPlayer设置音量:audioPlayer.volume+0.02];
UISlider*slider=volumeSliderView.子视图[0];
[滑块设置值:1.0动画:否];
}
否则如果(audioPlayer.volume>=1.0)
{
timerSecond=0;
定时器失效;
定时器=零;
}
}
问题是,当设置
MPMusicPlayerController.applicationMusicPlayer.volume


有没有办法在不显示iOS音量更改指示灯的情况下以最大设备音量播放声音文件?

8个月前,我正在尝试相关的事情,据我所知,如果存在MPVolumeView,iOS则不会显示系统音量更改指示灯


如果您实际上不想查看MPVolumeView,我想您可以将其隐藏在另一个视图后面。

您说您使用的是应用程序MusicLayer volume,但我看到您使用的是audioPlayer setVolume,它是一个AVAudioPlayer,您能澄清吗?据我所知。ApplicationMusicPlayer为iOS设置主音量,我使用AVAudioPlayer播放声音。这不对吗?我仿效了美国的例子。AVAudioPlayer播放声音并逐渐增加主音量的一小部分。我不认为你能做到这一点,你能做的是将音量设置为最大值,在更改前保留音量值,并在停止播放声音时恢复到原始值…我最终用类似的解决方案修复了它。我刚把MPVolumeView的原点设置在屏幕外