How to control "the system audio volume" of iOS

by Sep 5, 2017

Use C++Builder 10.2 to control audio volume of iOS.
I used the MPVolumeView class of iOS.
The MPVolumeView class is declared in “iOSapi.MediaPlayer.hpp”.

Include two files.

#include <iOSapi.MediaPlayer.hpp>
#include <iOSapi.UIKit.hpp>

Form design

Arrange “Up” and “Down” two TButton. Use this button to control the volume.

f:id:mojeld:20170905181055p:plain

Add MPVolumeView to the main form Class

Add “_di_MPVolumeView” and “_di_UISlider” to the form class.

class TForm1 : public TForm
{
__published:  // IDE-managed Components
    TButton *Button1;
    TLayout *Layout1;
    TButton *Button2;
    void __fastcall Button1Click(TObject *Sender);
    void __fastcall Button2Click(TObject *Sender);
private:  // User declarations
    _di_MPVolumeView    MPVolumeView1;
    _di_UISlider        slider1;
public:       // User declarations
    __fastcall TForm1(TComponent* Owner);
};

Main Form constructor

__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
    //Use "TMPVolumeView" to create "_di_MPVolumeView".
    MPVolumeView1 = TMPVolumeView::Create();
    for (int i = 0switch (i) {
        case 0:
            //Setting the _di_UISlider in the "MPVolumeView1".
            slider1 = TUISlider::Wrap(MPVolumeView1->subviews()->objectAtIndex(i));
            //Set the slider to 0.0.
            slider1->setValue(0.0

Code of volume down button

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    float i = slider1->value();
    slider1->setValue(i - 0.1

Code of volume up button

void __fastcall TForm1::Button2Click(TObject *Sender)
{
    float i = slider1->value();
    slider1->setValue(i + 0.1

Execute the program.