Latest 0.4.0
Homepage https://github.com/akramhussein/Mute
License MIT
Platforms ios 9.0
Frameworks Foundation, AudioToolbox
Authors

Version
License
Platform

There is no native iOS API to detect if the mute switch is enabled/disabled on a device.

The general principle to check if the device is muted is to play a short sound and detect the length it took to play.
From this length we can determine if it was muted or not.

This library is effectively a Swift variant of SoundSwitch.

Has a trigger rate of 1 second.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Usage

import UIKit
import Mute

class ViewController: UIViewController {

    @IBOutlet weak var label: UILabel! {
        didSet {
            self.label.text = ""
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Notify every 2 seconds
        Mute.shared.checkInterval = 2.0

        // Always notify on interval
        Mute.shared.alwaysNotify = true

        // Update label when notification received
        Mute.shared.notify = { [weak self] m in
            self?.label.text = m ? "Muted" : "Not Muted"
        }

        // Stop after 5 seconds
        DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
            Mute.shared.isPaused = true
        }

        // Re-start after 10 seconds
        DispatchQueue.main.asyncAfter(deadline: .now() + 10.0) {
            Mute.shared.isPaused = false
        }
    }

}

Requirements

Installation

Mute is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'Mute'

Author

Akram Hussein, [email protected]

License

Mute is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "Mute",
    "version": "0.4.0",
    "summary": "Detect if silent/mute switch is enabled/disabled",
    "description": "There is no native iOS API to detect if the mute switch is enabled/disabled on a device.nnThe general principle to check if the device is muted is to play a short sound and detect the length it took to play.nFrom this length we can determine if it was muted or not.nnThis library is a Swift variant of https://github.com/moshegottlieb/SoundSwitch.",
    "homepage": "https://github.com/akramhussein/Mute",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Akram Hussein": "[email protected]"
    },
    "source": {
        "git": "https://github.com/akramhussein/Mute.git",
        "tag": "0.4.0"
    },
    "social_media_url": "https://twitter.com/ahussein",
    "platforms": {
        "ios": "9.0"
    },
    "source_files": "Mute/Classes/**/*",
    "resource_bundles": {
        "Mute": [
            "Mute/Assets/*.caf"
        ]
    },
    "frameworks": [
        "Foundation",
        "AudioToolbox"
    ]
}

Pin It on Pinterest

Share This