2011年8月6日土曜日

AVPlayerのAVPlayerItemDidPlayToEndTimeNotificationを受けて終了すると、バスエラーになった。

iOS4.0から実装されたAVPlayerですが、再生の終了通知の"AVPlayerItemDidPlayToEndTimeNotification"を受けたときに適切な終了措置をとらないと、後のアプリの動作で不具合を起こすようです。この件では、アプリが不正終了して落ちました。
具体的には、cocos2dのreplaceSceneでシーンを入れ替えるときに発生しました。
なぜか、Adhocでデバイスにインストールしたときに現象が発生し、Debugでは発生しませんでした。
結局、対策はできて、とりあえず解決はしました。

デバイス:iPodTouch,iPhone3GS
OS:iOS4.3.5
iOS4.3sdk
Xcode3.2.6
Deployment Target iOS4.0

cocos2d 0.99.5

まず、アプリが落ちたときですが、コンソールでは以下のように出力されます。


Aug  5 19:55:35 unknown ReportCrash[162] <Notice>: Formulating crash report for process ???[161]
Aug  5 19:55:35 unknown com.apple.launchd[1] <Warning>: (UIKitApplication:com.yourcompany.???[0x9ac8]) Job appears to have crashed: Bus error: 10
Aug  5 19:55:35 unknown SpringBoard[28] <Warning>: Application '???' exited abnormally with signal 10: Bus error: 10
Aug  5 19:55:35 unknown ReportCrash[162] <Error>: libMobileGestalt loadBasebandMobileEquipmentInfo: CommCenter error: 1:45
Aug  5 19:55:35 unknown ReportCrash[162] <Error>: libMobileGestalt copyInternationalMobileEquipmentIdentity: Could not get mobile equipment info dictionary
Aug  5 19:55:35 unknown ReportCrash[162] <Error>: libMobileGestalt copyInternationalMobileEquipmentIdentity: Could not get mobile equipment info dictionary
Aug  5 19:55:36 unknown ReportCrash[162] <Error>: Saved crashreport to /var/mobile/Library/Logs/CrashReporter/???_2011-08-05-195535_iPodTouch-4th.plist using uid: 0 gid: 0, synthetic_euid: 501 egid: 0

Bus error: 10 といわれてもどうしたらよいか分かりませんでした。


ソース内では、AVPlayerItemDidPlayToEndTimeNotificationを通知名としてAVPlayerからの終了通知を受けるようにしています。

[[NSNotificationCenter defaultCenter] addObserver:self                                                                     selector:@selector(moviePlayBackDidFinishNotification:) 
name:AVPlayerItemDidPlayToEndTimeNotification
                    object:nil];

対策方法ですが、上のコードで登録されたセレクタの moviePlayBackDidFinishNotification 内で、以下のように一旦停止と再生終了時のUIを出すかどうかの設定を行えば、エラーは出なくなりました。


[self.player pause];
[self.player setActionAtItemEnd:AVPlayerActionAtItemEndNone];

原因は、まだ分かりませんが、無理にcocos2dと共存させているのが悪いのでしょうか?

0 件のコメント:

コメントを投稿

注: コメントを投稿できるのは、このブログのメンバーだけです。