Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would be careful calling <code>setValue</code> on an <code>MPVolumeView</code> since it probably won't do anything other than update the <em>appearance</em> of the slider, but not the actual device volume level. You would instead have to call <code>_commitVolumeChange</code> which is private API and will likely get your app rejected.</p> <p>A short answer to how to control volume: It really depends on what you're trying to control the volume of. </p> <p>If you want a "controls every sound within the app" sort of control then you can use an <code>MPVolumeView</code> but you <strong>cannot</strong> change it's value programmatically. You would then only be able to change the volume by either moving the slider with a touch or using the volume buttons on the side of the device. The best thing to do is create a global object that stores the volume level which any of your objects can read before they play their sound. </p> <p>If it's an <code>AVAudioPlayer</code> object, you'd create the object and use <code>[theAudioPlayerObject setVolume: someFloat];</code> where <code>someFloat</code> is a value between 0.0 and 1.0.</p> <p>If it's a <code>SystemSound</code> object, you can't control volume.</p> <p>If it's an <code>AudioQueue</code> you'd change it via <code>AudioQueueSetParameter</code></p> <p>Like I said.. it all depends on <em>how</em> you are playing the sound.</p> <p><strong>Update based on comment</strong></p> <p><a href="http://cocoawithlove.com/2008/09/streaming-and-playing-live-mp3-stream.html" rel="noreferrer">For that particular example</a>, you would set the volume like this:</p> <blockquote> <p>Add to the AudioStreamer.h file</p> </blockquote> <pre><code>- (void)setVolume:(float)Level; </code></pre> <blockquote> <p>Add to the AudioStreamer.m file</p> </blockquote> <pre><code>- (void)setVolume:(float)Level { OSStatus errorMsg = AudioQueueSetParameter(audioQueue, kAudioQueueParam_Volume, Level); if (errorMsg) { NSLog(@"AudioQueueSetParameter returned %d when setting the volume.", errorMsg); } } </code></pre> <blockquote> <p>Add to the view controller for where the volume knob will be (this goes in the .m file.. i just did this as a couple UIButtons real quick, you'll have to do your own) and set up an IBAction to change the volume for a given value (you can pass in 0.0 thru 1.0 as a float)</p> </blockquote> <pre><code>- (IBAction)volumeUp:(id)sender { [streamer setVolume:1.0]; } - (IBAction)volumeDown:(id)sender { [streamer setVolume:0.0]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload