but this is in objective-c,how can i used it for swift4
Look at doc in XCode for MPVolumeView
Aa far as I understand, you need to set volume with a slider (user interaction), not directly from code.
Use this class by embedding an instance of it in your view hierarchy. The following code snippet assumes you have placed an instance of the UIViewclass on a view using Interface Builder, sizing and positioning it as desired to contain the volume view. Point to the UIView instance with an outlet variable—named, in the case of this example, mpVolumeViewParentView. You would typically place code like that shown in Listing 1 in your viewDidLoad method.
myVolumeViewParentView.backgroundColor = UIColor.clear let myVolumeView = MPVolumeView(frame: myVolumeViewParentView.bounds) myVolumeViewParentView.addSubview(myVolumeView)
When an audio output route that does not support volume control, such as a car head unit, is active, the volume slider is replaced with the route name.
To instead display a volume slider as an alert, use the functions described in Global Volume Setting Methods.
You can't change the volume with this class while testing in the Simulator. These abilities only work on a device.
Did you finally make it work ?
If so, think to close the thread.