我可以在我的应用程序中收听 mp3 歌曲。我正在使用 AVPLAYER 这是一些代码
player = [[AVPlayer alloc] initWithURL:[NSURL fileURLWithPath:filePath]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playingItemDidEnd) name:AVPlayerItemDidPlayToEndTimeNotification object:player];
[player play];
timer = [NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(checkTime) userInfo:nil repeats:YES];
所以当我使用 ios 5.0 时,我在调试中 加载错误/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn: dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn,262):未找到符号:__CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 预计在:/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 在/System/Library/Frameworks/Security.framework/Versions/A/Security 2012-02-27 15:21:27.717 LifesMusic[4161:10703] 加载/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn: dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn, 262): 未找到符号:__CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 预计在:/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 在/System/Library/Frameworks/Security.framework/Versions/A/Security
但它仍然有效。但在 IOS 4.3 中它根本不起作用。有人可以帮我解决这个问题吗?谢谢
最佳答案
首先:你应该阅读苹果文档Multimedia Programming Guide并了解你在做什么......
还要确保您将 AV Foundation
框架链接到您的项目,正确导入它并且您的 Controller “监听”AVAudioPlayerDelegate。
在您的 Controller .h 文件中:
@property (nonatomic, retain) AVAudioPlayer *player;
在您的 Controller .m 文件中:
@synthesize player;
在您“播放”歌曲的方法中:
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource: @"song" ofType: @"mp3"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL error: nil];
[fileURL release];
self.player = newPlayer;
[newPlayer release];
[player setDelegate: self];
[player prepareToPlay];
[player play];
重复歌曲的委托(delegate)方法:
- (void) audioPlayerDidFinishPlaying:(AVAudioPlayer*)player successfully:(BOOL)completed {
if (completed == YES) {
[player play];
}
}
关于ios - avplayer 在 ios 4.3 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9465736/