Scrumdinger sample app does not play sound

I installed the Scrumdinger tutorial app using the links at: https://developer.apple.com/tutorials/app-dev-training/getting-started-with-scrumdinger

The ding sound does not play on my iPhone, the relevant code is:

import Foundation
import AVFoundation

extension AVPlayer {
    static let sharedDingPlayer: AVPlayer = {
        guard let url = Bundle.main.url(forResource: "ding", withExtension: "wav") else { fatalError("Failed to find sound file.") }
        return AVPlayer(url: url)
    }()
}


player.seek(to: .zero)
player.play()

If I create a separate sample app with just this code it does play the sound. However the sample Scrumdinger app does not play the "ding" sound.

Answered by sam181818 in 684712022

It seem that the sample code is missing the line try? AVAudioSession.sharedInstance().setCategory(.playback) without which the AVPlayer does not play the sound. Changing the code as follows fixes the issue

   var player: AVPlayer {
    try? AVAudioSession.sharedInstance().setCategory(.playback)
    return AVPlayer.sharedDingPlayer 
}
Accepted Answer

It seem that the sample code is missing the line try? AVAudioSession.sharedInstance().setCategory(.playback) without which the AVPlayer does not play the sound. Changing the code as follows fixes the issue

   var player: AVPlayer {
    try? AVAudioSession.sharedInstance().setCategory(.playback)
    return AVPlayer.sharedDingPlayer 
}

Did you copy the ding.wav file to your project Resource group?

Scrumdinger sample app does not play sound
 
 
Q