起動時にイントロ クリップを再生するアプリがあります。次のコードは- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
appDelegate.m 内にあり、見事に機能します。
NSLog(@"PLAY SOUND CLIP WHILE LOADING APP");
NSURL *clip = [[NSBundle mainBundle] URLForResource: @"intro" withExtension:@"caf"];
self.startupPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:clip error:NULL];
[self.startupPlayer play];
イントロ サウンドが終了する前にユーザーがビューを変更しても、引き続き再生されます。私はこのコード- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
を役立つとは考えていませんでしたが、そうではありませんでした。
-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
// Stop Sound
[self.startupPlayer stop];
}
ロード リクエストの直後に if ステートメントを配置すればうまくいくかもしれないと思ったのですが、うまくいきませんでした。例を参照してください:
NSLog(@"PLAY SOUND CLIP WHILE LOADING APP");
NSURL *clip = [[NSBundle mainBundle] URLForResource: @"intro" withExtension:@"caf"];
self.startupPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:clip error:NULL];
[self.startupPlayer play];
if ([viewDidDisappear == YES]) {
[self.startupPlayer stop];
}
クリップの再生が完了する前にユーザーがビューを変更した場合にイントロ サウンドを停止する提案があれば、すばらしいでしょう。ああ、アプリの他の部分で「viewWillDisappear」を使用して成功しましたが、この場合は「viewDidDisappear」を選択しました。後者も機能しなかったからです。だから私は困惑しています。前もって感謝します。
編集:だから、viewWillDisappear を MainViewController に移動し、デリゲートを呼び出しましたが、まだ運がありません。繰り返しますが、助けていただければ幸いです。