2012-02-27 99 views
1

我有能力聽我的應用程序的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中,它根本不工作。有人能幫我解決這個問題嗎?由於

回答

0

首先:你應該閱讀蘋果文檔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

0

我也收到了同樣的錯誤(錯誤OSStatus 1685348671)當我試圖在iOS 4.3播放MP3文件。

後來我發現這是mp3音效問題,使得它在iOS 4.3中不兼容。因此,我使用iTunes Player將現有的MP3音頻轉換爲新版本。現在它工作得很好,更好。

步驟:

打開在iTunes中目前的MP3聲音 選擇它並點擊「高級」菜單>>「創建MP3版本」 它西港島線創建當前音頻的副本。爲您的應用使用新創建的mp3文件。

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

相關問題