iOS code Modify volume

Source: Internet
Author: User

Recently in a project, you need the user to open the app, automatically adjust the volume to a value, and then studied a bit.

Before doing research on iOS sound, apple controls the input/output of iphone devices very tightly, because Apple controls the consistency of the user experience. For example: When the user pulls the headset down, Apple believes that the user does not want others to know what they are listening to, and then the voice is automatically paused. On the volume adjustment, Apple also adopted a similar strategy. Apple believes that the user does not need the app to specify the volume for him, because sometimes users feel uncomfortable. That's what Apple's development documentation says:

You cannot change device volume Programatically,however mpvolumeview (volume slider) are there to change device volume Only through user interaction.

Apple provides a way for users to manually modify the volume: Mpvolumeview. The user modifies the volume by dragging the slider bar, which is the following:



While Apple has blocked almost all of the code's way of controlling the volume, it can be modified with some proprietary methods. For example, we iterate over the subviews of Mpvolumeview, get uislider from it, and then modify the value of the slider. Although this approach can be modified, access to private classes has the risk of being rejected by the App Store. And do not know when Apple modifies the structure of the mpvolumeview, such a method is not.

Here is a small trick that can modify the volume, an Apple's way to kill it:

mpmusicplayercontroller* Musiccontroller = [Mpmusicplayercontroller applicationmusicplayer];musiccontroller.volume = 0.2;

You need to add mediaplayer.framework before using.

Why is it that Apple wants to kill and can't kill it? This method was added to the iOS3.0, when it was estimated that there was no "do not allow code to modify the volume" specification; later, at 7.0, the method was depress out, indicating that Apple wanted to kill it. But for a continuous improvement of the system, it is generally to do forward compatibility, otherwise there will be a tragedy like WP6-WP7-WP8. So Apple was very cautious about getting rid of a method, and finally left it behind, leaving a window in its mighty walls for development.

iOS code Modify volume

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.