AVAudioPath无法正常工作-Swift

普拉纳夫·瓦德瓦(Pranav Wadhwa)

我正在尝试根据用户选择的乐器播放歌曲。这是我的代码:

@IBAction func play(sender:AnyObject){

    if isPlaying == false {
        player.play()
        isPlaying = true
    }

}
@IBAction func stop(sender: AnyObject) {

    if isPlaying == true {
        player.stop()
        isPlaying = false
    }

}
@IBAction func pause(sender: AnyObject) {

    if isPlaying == true {
        isPlaying = false
        player.pause()
    }

}



var player = AVAudioPlayer()
var audioPath = NSBundle.mainBundle().pathForResource("Iditarod Bass", ofType: "m4a")

var isPlaying = Bool()

@IBOutlet var instrumentSelect: UISegmentedControl!


@IBAction func didChangeInstrument(sender: AnyObject) {

    if isPlaying == false {

        if instrumentSelect.selectedSegmentIndex == 0 {

            audioPath = NSBundle.mainBundle().pathForResource("Iditarod Bass", ofType: "m4a")

            do {
                try player = AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
            } catch {


            }

        } else if instrumentSelect.selectedSegmentIndex == 1 {

            audioPath = NSBundle.mainBundle().pathForResource("Iditarod Cello", ofType: "m4a")

                do {
                    try player = AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
                } catch {


                }


        } else if instrumentSelect.selectedSegmentIndex == 2 {

            audioPath = NSBundle.mainBundle().pathForResource("Iditarod Viola", ofType: "m4a")
            do {
                try player = AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
            } catch {


            }

        } else if instrumentSelect.selectedSegmentIndex == 3 {

            audioPath = NSBundle.mainBundle().pathForResource("Iditarod Violin 1", ofType: "m4a")

            do {
                try player = AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
            } catch {


            }

        } else if instrumentSelect.selectedSegmentIndex == 4 {

            audioPath = NSBundle.mainBundle().pathForResource("Iditarod Violin 2", ofType: "m4a")

            do {
                try player = AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))

            } catch {


            }


        }
    }

}

instrumentSelect.selectedSegmentIndex == 1以外的其他都工作正常我不知道为什么 我得到一个EXC_BAD_INSTRUCTIONfatal error: unexpectedly found nil while unwrapping an Optional value该文件运行正常,我已经多次清理了该项目。我正确键入了所有内容。为什么那一个不起作用?我对此感到非常困惑,也感谢您的帮助。

普拉纳夫·瓦德瓦(Pranav Wadhwa)

该文件未添加到应用程序目标中。它仅被添加到项目中。感谢@matt为我提供帮助。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Swift Segue无法正常工作?

来自分类Dev

Swift BringSubViewToFront无法正常工作

来自分类Dev

performSegueWithIdentifier无法正常工作-Swift

来自分类Dev

Swift Segue无法正常工作

来自分类Dev

Swift NSTimer无法正常工作

来自分类Dev

Swift colorWithAlphaComponent()无法正常工作

来自分类Dev

performSegueWithIdentifier无法正常工作-Swift

来自分类Dev

AsyncDisplayKit invalidateCalculatedSize Swift无法正常工作

来自分类Dev

Swift派生属性KVO无法正常工作

来自分类Dev

Swift NSUserNotificationCenter didActivateNotification无法正常工作

来自分类Dev

Swift上的数组比较无法正常工作

来自分类Dev

SKTransition crossFadeWithDuration无法在Swift中正常工作

来自分类Dev

键盘高度在Swift中无法正常工作

来自分类Dev

Swift Uiview背景动画无法正常工作

来自分类Dev

无法查看并使其正常工作-Swift

来自分类Dev

XPath在Swift中无法正常工作

来自分类Dev

Swift Eureka SelectableSection baseValue无法正常工作

来自分类Dev

Swift-NSDateFormater无法正常工作

来自分类Dev

iOS/Swift - If/if else 语句无法正常工作

来自分类Dev

Swift 4 NSLayoutConstraint 无法正常工作

来自分类Dev

Swift Delete无法正常工作/无法在表格视图中显示

来自分类Dev

Swift嵌套查询中的Firebase无法正常工作

来自分类Dev

为什么类型转换在Swift 2.0中无法正常工作?

来自分类Dev

Xcode 6 Swift代码完成无法正常工作

来自分类Dev

覆盖init(coder aDecoder:NSCoder!)无法正常工作-Swift

来自分类Dev

大小类在Swift 2.0中无法正常工作

来自分类Dev

旧的swift代码无法正常工作(动画UIView)

来自分类Dev

Swift 2.0初始化嵌套字典无法正常工作

来自分类Dev

iOS Swift动画有时无法正常工作

Related 相关文章

热门标签

归档