如何解决iPhone 5c的钢琴应用程序问题中的“无声音”?

时间:2019-05-19 23:00:48

标签: ios swift avfoundation avaudioplayer

我正在使用iOS 10.3在iPhone 5c的钢琴应用程序上工作,希望在按下时获得声音,但在实际的iPhone 5c上进行测试时却没有声音。

我已经尝试在所有模拟器上运行代码并且可以运行,但是在实际的iPhone 5c上进行测试时唯一的问题是没有声音。

import UIKit
import AVFoundation

class ViewController: UIViewController, AVAudioPlayerDelegate {
    var audioPlayer = AVAudioPlayer()
    let soundArray = ["note1", "note2","note3","note4","note5","note6","note7"]
    var selectedSoundFileName : String = ""

    @IBAction func notePressed(_ sender: UIButton) {
        selectedSoundFileName = soundArray[sender.tag]
        print(selectedSoundFileName)
        playSound()
    }

    func playSound(){
        let soundURL = Bundle.main.url(forResource: selectedSoundFileName , withExtension: "wav")

        do{
            audioPlayer = try AVAudioPlayer(contentsOf: soundURL! )
        } catch{
            print(error)
        }

        audioPlayer.play()
    }
}

预期的o / p =要获取所有包含在WAV文件中的钢琴音色。

实际o / p =在实际的iPhone中根本没有声音(注意:声音仅在模拟器(即iPhone Xr)上有效

0 个答案:

没有答案