【发布时间】:2010-06-25 16:31:46
【问题描述】:
我在使用 AVAudioPlayer 类时遇到了一个奇怪的问题。 每次我尝试访问其中一个属性时,它们都是空的。
// 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];
有什么想法吗?
编辑:奇怪的是,当我将 isPlaying 保存到 bool 并打印 bool 时,我得到了一个值...
【问题讨论】:
-
你有没有设法解决这个问题?我有同样的问题,无法解决。
标签: iphone cocoa xcode avaudioplayer