2012-02-28 6 views
0

私はiPhoneアプリにAVAudioPlayerを実装しましたが、再生されているオーディオが大きすぎます。少し音を抑えるために、音量を0.2fに変更して効果があるかどうかを確認しました。音量はまったく同じです。私が使用しているコードは次のとおりです。AVAudioPlayer too loud

NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Blip.mp3", [[NSBundle mainBundle] resourcePath]]]; 

NSError *error; 
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; 
audioPlayer.numberOfLoops = 0; 
[audioPlayer setVolume:0.2f]; 

if (audioPlayer == nil) 
    NSLog(@"Whoopsies, there was an error with the sound!"); 
else 
    [audioPlayer play]; 

なぜ音量が下がりませんか?

どうすればいいですか?

ありがとうございます!

答えて

1

あなたのコードを置き換え:

audioPlayer.volume = 0.2; 

希望すると、これが役立ちます。

+0

私はこれらの2行のコードが同じことをしていると確信しています。 – gregheo

+0

元々試してみましたが、うまくいきませんでした:( –

+0

これを試してみてください。NSStringの代わりにNSURLの使い方と関係があります。 \t NSString * name = [[NSString alloc] initWithFormat: @ "ブリップ"]; \t NSStringの*ソース= [[NSBundle mainBundle] pathForResource:名ofType: "mp3" @]; \t(audioPlayer)であれば{ \t \t [audioPlayer]止める; \t \t audioPlayer =ゼロ、 \t} \t audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fil eURLWithPath:source]エラー:NULL]; \t audioPlayer.delegate = self; \t audioPlayer.volume = 0.2; \t [audioPlayer play]; –

0

Apple Audio & Video Coding How-To'sで説明されているように、ハードウェアボリュームを設定することはできません。

How do I access the hardware volume controller?
Global system volume, including your application's volume, is handled by iPhone OS and is not accessible by applications.

AVAudioPlayerインスタンスのボリュームは、相対的体積です。 2つのサウンドを2つのAVAudioPlayerインスタンスで再生し、互いの音量を設定することができます。

EDIT:

あなたのデバイスのグローバルボリュームをコントロールしたい場合は、あなたがMPVolumeViewを使用することができます。次のコードで

[audioPlayer setVolume:0.2f]; 

MPVolumeView *myVolumeView = [[MPVolumeView alloc] initWithFrame:mpVolumeViewParentView.bounds]; 
[mpVolumeViewParentView addSubview:myVolumeView]; 
[myVolumeView release]; 
+0

したがって、ハードウェアのボリュームとは異なる特定の音量でサウンドを再生するにはどうすればよいですか?これを行う別の方法はありますか? –

+0

TweetBotなどの他のアプリはそれをしますか? –

+0

['MPVolumeView'](https://developer.apple.com/library/ios/#DOCUMENTATION/MediaPlayer/Reference/MPVolumeView_Class/Reference/Reference.html)が役立つと思います。 – dom