AVAudioPlayer isPlaying始终返回null

编程入门 行业动态 更新时间:2024-10-24 23:18:30
本文介绍了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

本文发布于:2023-11-14 19:13:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1588301.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:AVAudioPlayer   isPlaying   null

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!