本文介绍了AVAudioPlayer isPlaying始终返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在AVAudioPlayer类中遇到了一个奇怪的问题. 每次我尝试访问其中一个属性时,它们都为空.
I'm experiencing an odd problem with AVAudioPlayer class. Everytime I try to access one of it's properties they are null.
// Get the file path to the song to play. NSString *filePath = [[[NSBundle mainBundle] pathForResource:pSound.fileName ofType:pSound.fileType] retain]; // Convert the file path to a URL. NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath]; NSError* err; //Initialize the AVAudioPlayer self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&err]; if( err ){ NSLog(@"Initializing failed with reason: %@", [err localizedDescription]); } else{ [self.audioPlayer setDelegate:self]; [self.audioPlayer prepareToPlay]; self.playCount = self.playCount + 1; NSLog(@"%@", [self.audioPlayer isPlaying]); //this displays null; also if I call it at a later time }; [filePath release]; [fileURL release];有什么想法吗?
奇怪的是,当我保存isPlay到bool并打印bool时,我得到了一个值...
Oddly enough when I save isPlaying to a bool and print the bool I get a value...
推荐答案NSLog(@"%@", [self.audioPlayer isPlaying]);
%@-表示您要打印[yourObject toString]的结果 因此,如果您要检查[self.audioPlayer isPlaying]返回的布尔值-您应该使用%d.
%@ - mean that you want to print result of [yourObject toString] so if you want to check bool value returned by [self.audioPlayer isPlaying] - you should use %d.
p.s.请勿致电[audioPlayer播放]; ;)
p.s. don't foget call [audioPlayer play]; ;)
更多推荐
AVAudioPlayer isPlaying始终返回null
发布评论