avplayer不工作在ios 4.3

问题描述:

我有能力听我的应用程序的MP3歌曲。我使用AVPLAYER 下面是一些代码avplayer不工作在ios 4.3

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/CoreFou ndation in /System/Library/Frameworks/Security.framework/Versions/A/Security 2012-02-27 15:21:27.717 LifesMusic [4161:10703] Error loading /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 in /System/Library/Frameworks/Security.framework/Versions/A/Security

但它仍然有效。但在IOS 4.3中,它根本不工作。有人能帮我解决这个问题吗?由于

首先:你应该阅读苹果文档Multimedia Programming Guide,并了解你在做什么?

另外,还要确保你链接的AV Foundation框架到您的项目,进口得当,你的控制器“监听” AVAudioPlayerDelegate。

在你的控制器的.h文件:

@property (nonatomic, retain) AVAudioPlayer *player; 

在你的控制器的.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]; 

委托方法重复歌曲:

- (void) audioPlayerDidFinishPlaying:(AVAudioPlayer*)player successfully:(BOOL)completed { 
    if (completed == YES) { 
     [player play]; 
    } 
} 
+0

我有avplayer不是avaudioplayer – 2012-02-27 13:50:28

+0

但是AVAudioPlayer被推荐用于音频......所以你应该按照苹果推荐 – dom 2012-02-27 13:52:02

+0

确定。谢谢!我会制作avaudioplayer – 2012-02-27 13:53:34

我也收到了同样的错误(错误OSStatus 1685348671)当我试图在iOS 4.3播放MP3文件。

后来我发现这是mp3音效问题,使得它在iOS 4.3中不兼容。因此,我使用iTunes Player将现有的MP3音频转换为新版本。现在它工作得很好,更好。

步骤:

打开在iTunes中目前的MP3声音 选择它并点击“高级”菜单>>“创建MP3版本” 它西港岛线创建当前音频的副本。为您的应用使用新创建的mp3文件。

它帮助了我。我希望它也可以帮助其他人。祝一切顺利!