“无法将类型'AVAudioPlayer.Type'的值转换为预期的参数类型" [英] "Cannot convert value of type 'AVAudioPlayer.Type' to expected argument type"

查看:82
本文介绍了“无法将类型'AVAudioPlayer.Type'的值转换为预期的参数类型"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在播放audioPlayerDidFinish函数时遇到问题.我已经将AVAudioPlayerDelegate添加到我的视图控制器类中并定义了该函数.当我调用该函数时,出现错误无法将类型'AVAudioPlayer.Type'的值转换为预期的参数类型"我在做什么错?让我知道是否需要添加更多代码供您查看.

I'm having trouble with the function audioPlayerDidFinish playing. I have added the AVAudioPlayerDelegate to my view controller class and defined the function. When I call the function I get the error "Cannot convert value of type 'AVAudioPlayer.Type' to expected argument type" What am I doing wrong? Let me know if I need to add more code for you to see.

    func buttonPressed() {
    if currentSound == sound {
        currentSound = "None"
        activateBlankCircle()
        audioPlayer.stop()
    }
    else {
        currentSound = sound
        audioPlayer.prepareToPlay()
        activateRedCircle()
        playSound()
        audioPlayerDidFinishPlaying(AVAudioPlayer, successfully: Bool)
        //Cannot convert value of type 'AVAudioPlayer.Type' to expected argument type

    }

}

推荐答案

委托方法不应由委托本身调用.

Delegate methods should not be called by the delegate itself.

audioPlayerDidFinishPlaying这是一个委托方法.您应该实现它(具有)并将self设置为音频播放器的委托. AVAudioPlayer将在适当的时间(即当它结束播放声音时)调用该方法.

audioPlayerDidFinishPlaying here is a delegate method. You are supposed to implement it (which you have) and set self as the audio player's delegate. The method will be called by the AVAudioPlayer at an appropriate time i.e. when it finishes playing a sound.

因此,您应该删除对audioPlayerDidFinishPlaying的调用,然后一切正常.从外观上,您正在实现开始/停止播放按钮.如果要在播放器结束播放时执行某些操作,可以在viewDidLoad中将self设置为audioPlayer.delegate.完成播放声音后,将调用该方法.

So you should remove the call to audioPlayerDidFinishPlaying and everything should work fine. From the looks for it, you are implementing a start/stop playing button. If you want to do something when the player finishes playing, you can set self as the audioPlayer.delegate in viewDidLoad. And the method will be called when it finishes playing a sound.

这篇关于“无法将类型'AVAudioPlayer.Type'的值转换为预期的参数类型"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆