Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios audioPlayer.isplay语句上的线程1错误_Ios_Swift_If Statement_Avaudioplayer - Fatal编程技术网

Ios audioPlayer.isplay语句上的线程1错误

Ios audioPlayer.isplay语句上的线程1错误,ios,swift,if-statement,avaudioplayer,Ios,Swift,If Statement,Avaudioplayer,当我的audioPlayer加载viewDidLoad时,我正在尝试执行if语句。基本上说,如果音频播放器正在播放,则暂停播放。像这样: override func viewDidLoad() { super.viewDidLoad() if audioPlayer.isPlaying { audioPlayer.pause() } } 但是,在第5行(启动if语句),我得到了错误 线程1:EXC\u错误访问(代

当我的audioPlayer加载viewDidLoad时,我正在尝试执行if语句。基本上说,如果音频播放器正在播放,则暂停播放。像这样:

override func viewDidLoad()
    {
        super.viewDidLoad()

        if audioPlayer.isPlaying {
            audioPlayer.pause()
        }
}
但是,在第5行(启动if语句),我得到了错误

线程1:EXC\u错误访问(代码=1,地址=0x48)


我怎样才能解决这个问题?谢谢你的帮助

此处不能使用默认的
NSObject
初始值设定项-
AVAudioPlayer
不会覆盖它,因此它不会设置
isplay
属性(或其任何其他属性)。您必须使用它实际实现的其中一个初始值设定项:

/* For all of these init calls, if a return value of nil is given you can check outError to see what the problem was.
 If not nil, then the object is usable for playing
*/

/* all data must be in the form of an audio file understood by CoreAudio */
public init(contentsOf url: URL) throws

public init(data: Data) throws


/* The file type hint is a constant defined in AVMediaFormat.h whose value is a UTI for a file format. e.g. AVFileTypeAIFF. */
/* Sometimes the type of a file cannot be determined from the data, or it is actually corrupt. The file type hint tells the parser what kind of data to look for so that files which are not self identifying or possibly even corrupt can be successfully parsed. */
@available(iOS 7.0, *)
public init(contentsOf url: URL, fileTypeHint utiString: String?) throws

@available(iOS 7.0, *)
public init(data: Data, fileTypeHint utiString: String?) throws

您不能在此处使用默认的
NSObject
初始值设定项-
AVAudioPlayer
不会覆盖它,因此它不会设置
isplay
属性(或其任何其他属性)。您必须使用它实际实现的其中一个初始值设定项:

/* For all of these init calls, if a return value of nil is given you can check outError to see what the problem was.
 If not nil, then the object is usable for playing
*/

/* all data must be in the form of an audio file understood by CoreAudio */
public init(contentsOf url: URL) throws

public init(data: Data) throws


/* The file type hint is a constant defined in AVMediaFormat.h whose value is a UTI for a file format. e.g. AVFileTypeAIFF. */
/* Sometimes the type of a file cannot be determined from the data, or it is actually corrupt. The file type hint tells the parser what kind of data to look for so that files which are not self identifying or possibly even corrupt can be successfully parsed. */
@available(iOS 7.0, *)
public init(contentsOf url: URL, fileTypeHint utiString: String?) throws

@available(iOS 7.0, *)
public init(data: Data, fileTypeHint utiString: String?) throws

很难说没有更多的代码或更多的错误细节,但我的第一个猜测是,
audioPlayer
是一个隐式展开的可选选项,在这一点上它是零。基本上,audioPlayer是由'var audioPlayer=AVAudioPlayer()'制作的,同样对于错误,这就是我得到的所有lol。如果没有更多的代码或更多的错误细节,很难说,但我的第一个猜测是,
audioPlayer
是一个隐式展开的可选项,在这一点上是零。基本上,audioPlayer是由'var audioPlayer=AVAudioPlayer()'制作的。同样,对于这个错误,我得到的lol就是这些。