avplayer has no sounds when play video
Check if the iPhone has silent mode engaged, it is a button above the 2 top left buttons. A toggle switch that allows silent mode.
For Swift 4.2, put following lines in viewDidLoad
do {
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: [])
}
catch {
print("Setting category to AVAudioSessionCategoryPlayback failed.")
}
For Swift 5
do {
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: [])
}
catch {
print("Setting category to AVAudioSessionCategoryPlayback failed.")
}
Check your phone is silent mode or not. If it is silent try add code below to viewDidLoad
:
Swift 2.3
try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, withOptions: [])
Swift 3
try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, with: [])
Swift 4.2
try! AVAudioSession.sharedInstance().setCategory(.playback, options: [])
Or just
try! AVAudioSession.sharedInstance().setCategory(.playback)