How to Change Device Volume on iOS - Not Music Volume

How can i change current system volume without making the current music stopping

Note that while what you're describing is likely possible (I've shipped a product that does this in order to interoperate with custom hardware), it's completely unsupported, is likely to break in the future (it broke a couple of times for me when the OS upgraded), and can potentially get your app removed from AppStore. Given the changes we've seen in recent releases, I expect the tricks used to pull this off won't work at all in future OS versions. The feature you're describing is not permitted by Apple. As the docs for AVAudioSession.outputVolume note: "Only the user can directly set the system volume. Provide a volume control in your app, using MPVolumeView, to provide the interface to adjust the system volume."

There is no MPVolumeView.setVolume method in the public API, so it's unclear what you're actually doing here. You should likely include the code for the extension I assume you've written.

That said, the reason it's pausing is because you told it to pause here:

    try! AVAudioSession.sharedInstance().setActive(true)

The default behavior of this line is to take control of the audio session in .playback mode, which will interrupt all background sessions. Ideally you should not activate the audio session at all if you don't plan to play audio. If you do, then you should set the category to .ambient (to indicate that audio is not important for your app) or you should pass the option .mixWithOthers (to indicate it is important, but you still want other sessions to continue playing).

Depending on your actual goals, a better solution to this is likely to pass the option .duckOthers, which will reduce the volume of other apps in a supported way.

How to get the volume of the music/audio playing on an IOS device?

You can't do what you're asking to do with music playing from the Music app, as the sound does not belong to you. If you play the sound yourself with an AVAudioPlayer you can use its peakPowerForChannel method.

how to Control iOS system Volume using a UISlider

I love new learners... Simple answer for you...

First create a UIView in your StoryBoard, where you want to put a volume slider.
Now create a IBOutlet for that view in your ViewController implementation.

for ex:

@property (nonatomic,strong) IBOutlet UIView* volumeView;

Now in the viewDidLoad method write the following code:

MPVolumeView *mpVolumeView = [[MPVolumeView alloc]initWithFrame:self.volumeView.bounds];
[self.volumeView addSubview:mpVolumeView];
[mpVolumeView sizeToFit];

Now you will have volume control in your app...

Note: this code will not work for a simulator.

cheers.

How to change an iOS device volume programmatically?

I'm pretty sure that it is not possible to control the actual device volume (as this would also be a bit obtrusive) Controlling some media you're playing is another thing. You could however look into MPVolumeView: https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPVolumeView_Class/index.html for displaying a view for setting the volume.

The question has also been discussed here:
How to change device Volume on iOS - not music volume

How to change ios volume in swift with help UISlider

The MPVolumeView class is designed to let you do exactly this. It's in MediaPlayer framework. So, add that to your app to make things build correctly.

You create it and make it visible the way you instantiate any other subclass of UIView, which you probably know by now.

You can provide your own frame and use this to change the system volume.

var wrapperView = UIView(frame: CGRectMake(30, 200, 260, 20))
self.view.backgroundColor = UIColor.clearColor()
self.view.addSubview(wrapperView)

// 3
var volumeView = MPVolumeView(frame: wrapperView.bounds)
wrapperView.addSubview(volumeView)

For more help you can look here Controlling system volume using swift

iOS Volume Control via Bluetooth

There is no supported way to modify the system volume. This has been intentionally removed (there used to be supported ways).

There is a deprecated way (since iOS 7) that currently works, but may go away in any future release. You can use [[MPMusicPlayerController systemMusicPlayer] setVolume:] to set the master volume.

The new supported way to change the system volume is to open an MPVolumeView and let the user modify the volume. But there's no programmatic interface. You can hunt around in the view for the sliders and adjust them through, though. This is really fragile; sometimes the structure changes between OS versions, and Apple may move this view into another process in the future (as they've done with several other views that they don't want you messing with). I do not recommend this approach and am not going to write up code to do it (since the deprecated setVolume: still works). But it is possible.

Again, this is all unsupported stuff, and Apple may reject your app over it.

Adjusting the Volume using MPVolume for a music player, iOS

Try to launch your project on the real device. The simulator doesn't display MPVolumeSlider.

Use this code, what by means of UISlider to change value of a system sound:

@IBAction func volumeSliderChanging(sender: UISlider) {
let volumeSlider = (MPVolumeView().subviews.filter { NSStringFromClass($0.classForCoder) == "MPVolumeSlider" }.first as! UISlider)
volumeSlider.setValue(sender.value, animated: false)
}

Be convinced that MediaPlayer framework is connected:

import MediaPlayer

Good luck!



Related Topics



Leave a reply



Submit