AVAudioPlayer 的 IOS 最大音量级别?

发布于 2025-01-05 01:32:53 字数 528 浏览 0 评论 0原文

我使用 AVAudioPlayer 播放 .caf 文件。我的问题是:对于我的目的来说,声音不够响亮。由于 iPhone 的铃声更大,我想知道如何归档此卷。 我已经尝试操作 .caf 文件,但没有真正成功。有什么想法吗?

我到目前为止使用的代码:

    AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: url error: nil];
self.appSoundPlayer = newPlayer;
[newPlayer release];
[appSoundPlayer prepareToPlay];
[appSoundPlayer setVolume: 0.8];
[appSoundPlayer setDelegate: self];
    [appSoundPlayer play];

编辑:

[appSoundPlayer setVolume: 1.0];

Thx 马丁

I use the AVAudioPlayer to play a .caf file. My problem is: it is not loud enough for my purpose. Since the ringer sound of the IPhone is much louder I was wondering how I can archive this volume.
I already tried to manipulate the .caf file but with no real success. Any ideas?

The code I use so far:

    AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: url error: nil];
self.appSoundPlayer = newPlayer;
[newPlayer release];
[appSoundPlayer prepareToPlay];
[appSoundPlayer setVolume: 0.8];
[appSoundPlayer setDelegate: self];
    [appSoundPlayer play];

Edit:

[appSoundPlayer setVolume: 1.0];

Thx
Martin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏尔 2025-01-12 01:32:53

您始终可以将音量设置为实际最大值,例如:

[appSoundPlayer setVolume: 1.0];

除此之外,您可能必须编辑文件本身。

You could always set the volume to actual maximum eg:

[appSoundPlayer setVolume: 1.0];

Other than that, you probably will have to edit the file itself.

云雾 2025-01-12 01:32:53

马丁,你确定系统音量开到最大了吗?如果没有,您需要使用 MPMusicPlayerController 将系统音量调到最大,而不仅仅是 avaudioplayer 的最大音量。您可以将其调高到声音剪辑的长度,然后将其设置回用户设置的原始音量。

// Import headers. Link to "MediaPlayer Framework"
#import <MediaPlayer/MediaPlayer.h>

//set up audio session
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:NULL];

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);

NSURL *soundUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"HsTR_soundEFX_2-1" ofType:@"mp3"]];
audioAlert= [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
audioAlert.delegate = self;
[audioAlert prepareToPlay];//audioAlert is an AVAudioPLayer declared in header

//and whereever you want to play the sound, call the lines below
float currentVolume=[MPMusicPlayerController applicationMusicPlayer].volume; //grab current User volume
[[MPMusicPlayerController applicationMusicPlayer] setVolume:1.0];//set system vol to max
[audioAlert play];
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(setVolumeBackToNormal)userInfo:nil repeats:NO];

//and the setVolumeBackToNormal function calls this line below
[[MPMusicPlayerController applicationMusicPlayer]setVolume:currentVolume];//returns volume to original setting

Martin, have you ensured the system volume is to a maximum? If not, you want to use the MPMusicPlayerController to turn up the system volume to the max, and not just the avaudioplayer maximum. You can turn it up for the length of your sound clip and then set it back to the original volume the user had it set at.

// Import headers. Link to "MediaPlayer Framework"
#import <MediaPlayer/MediaPlayer.h>

//set up audio session
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:NULL];

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);

NSURL *soundUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"HsTR_soundEFX_2-1" ofType:@"mp3"]];
audioAlert= [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
audioAlert.delegate = self;
[audioAlert prepareToPlay];//audioAlert is an AVAudioPLayer declared in header

//and whereever you want to play the sound, call the lines below
float currentVolume=[MPMusicPlayerController applicationMusicPlayer].volume; //grab current User volume
[[MPMusicPlayerController applicationMusicPlayer] setVolume:1.0];//set system vol to max
[audioAlert play];
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(setVolumeBackToNormal)userInfo:nil repeats:NO];

//and the setVolumeBackToNormal function calls this line below
[[MPMusicPlayerController applicationMusicPlayer]setVolume:currentVolume];//returns volume to original setting
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文