Do not use AVPlayerViewController , as it is a full-screen, black box, video player.
Instead, create your own view controller, say, a toolbar and controls available in the OS (play, pause, stop, etc.) and attach them to yours AVAudioPlayer. Here's what your own view controller code looks like:
Maintain Player Instance
var audioPlayer:AVAudioPlayer!
@IBOutlet weak var playProgress: UIProgressView!
Example: Playback
@IBAction func doPlayAction(_ sender: AnyObject) {
do {
try audioPlayer = AVAudioPlayer(contentsOf: audioRecorder.url)
audioPlayer.play()
} catch {}
}
Example: Stop
@IBAction func doStopAction(_ sender: AnyObject) {
if let audioPlayer = self.audioPlayer {
audioPlayer.stop()
}
}
Example: Tracking Progress
func playerProgress() {
var progress = Float(0)
if let audioPlayer = audioPlayer {
progress = ((audioPlayer.duration > 0)
? Float(audioPlayer.currentTime/audioPlayer.duration)
: 0)
}
playProgress.setProgress(progress, animated: true)
}
I published an example of recording and playback using the methodology outlined in this answer.

βΊ GitHub .