Audio control - iOS

In iOS apps you should always provide a pause or stop button for media. When using AVPlayer, you should use play and pause methods.

You should also make sure that audio is played through the correct channel. Use AVAudioSession in combination with AVAudioSessionCategory to achieve this.

The following channels are available:

// Set audio channel
try AVAudioSession.sharedInstance().setCategory(
    .playback, 
    mode: .default, 
    options: []
)

// Provide media controls
@objc private func click(_ sender: UIButton) {
    if player.timeControlStatus == .playing {
        player.pause()
    } else {
        player.play()
    }
}